home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hamradio / logic.zip / LOGIC11 / LOGIC.DOC < prev    next >
Text File  |  1995-03-04  |  115KB  |  2,337 lines

  1.                               LOGIC CIRCUIT ANALYSIS
  2.                               Version 1.1, March 1995
  3.                        Copyright 1991-1995, Arthur Tanzella
  4.                                 All Rights Reserved
  5.  
  6. The "Logic Circuit Analysis" program is an educational tool.  It introduces
  7. the user to logic concepts and digital computers.  The user can create and
  8. evaluate logic circuits on the computer screen.  This documentation or the
  9. online tutor functions as a tutorial to learn about logic and digital
  10. computers.  Numerous sample circuits teach the user how to design and build
  11. computer circuits.
  12.  
  13. ACKNOWLEDGEMENTS
  14.  
  15. I would like to thank the following people who are my good friends, and have
  16. contributed significantly to this program.  Their contributions were in the
  17. testing of the program and giving suggestions to make this program and
  18. documentation easier to use and read.
  19.  
  20.                                    Warren Cella
  21.                                   Mike Weisfield
  22.  
  23. LICENSE AGREEMENT
  24.  
  25. Logic Circuit Analysis is a "Shareware Program" provided at no charge to the
  26. user for a one week evaluation period.  Feel free to share it with your
  27. friends, but please do not give it away altered or as part of another system. 
  28. The essence of "user-supported" software is to provide users with quality
  29. software without high prices, and yet to provide incentive for programmers to
  30. continue to develop new products.  If you find this program useful and
  31. continue to use the program after the one week evaluation period, please make
  32. a registration payment of $20 (US) to the following:
  33.  
  34.           Arthur Tanzella
  35.           4613 Clubvue Drive
  36.           Pittsburgh, PA 15236-4803
  37.           USA
  38.  
  39. To register this program print and fill out the "REGISTER.DOC" file and send
  40. it, with the $20 (US) registration fee, to the above address.
  41.  
  42. The $20 (US) registration fee will license one copy for use on one computer at
  43. a time.  You must treat this software just like a book.  As an example, any
  44. number of people can use this software if there is no possibility of using it
  45. on two computers simultaneously.  Treat the software just like a book that
  46. cannot be read by two people in two different locations simultaneously.
  47.  
  48. Users of Logic Circuit Analysis must accept this disclaimer of the warranty:
  49. "Logic Circuit Analysis" is supplied as is.  The author disclaims all
  50. warranties, expressed or implied, including, without limitation, the
  51. warranties of merchantability and of fitness for any purpose. The author
  52. assumes no liability for damages, direct or consequential, which may result
  53. from the use of "Logic Circuit Analysis."
  54.  
  55. Commercial users of Logic Circuit Analysis must register and pay for their
  56. copies of Logic Circuit Analysis within 30 days of first use or their license
  57. is withdrawn.  Site-License arrangements are available by contacting Arthur
  58. Tanzella at the above address.
  59.  
  60. Anyone distributing Logic Circuit Analysis for any kind of remuneration must
  61. first contact Arthur Tanzella at the address above for authorization.  This
  62. authorization is granted automatically to distributors recognized by the
  63. Association of Shareware Professionals (ASP) as adhering to its guidelines for
  64. shareware distributors, and such distributors may begin offering Logic Circuit
  65. Analysis immediately.  However, you must advise Arthur Tanzella so you can be
  66. kept up-to-date with the latest version of the Logic Circuit Analysis program.
  67.  
  68. You are encouraged to pass a copy of Logic Circuit Analysis along to your
  69. friends for evaluation.  Please encourage them to register their copy if they
  70. plan to continue using it.  
  71.  
  72. All registered users will receive a copy of the latest version of the Logic
  73. Circuit Analysis program.  Also, registered users will receive a supplementary
  74. library of commonly used 7400 series circuits.  You could design circuits on
  75. the screen using the 7400 series circuits contained in this library.  If you
  76. have any comments or problems with this program, you can contact me at the
  77. address above or send an E-mail message via CompuServe to Arthur Tanzella
  78. 71175,76.  All registered users will receive support for a minimum of three
  79. months from the time they registered.
  80.  
  81. ASP OMBUDSMAN
  82.  
  83. The author is a member of the Association of Shareware Professionals (ASP). 
  84. The ASP wants to make sure that the shareware principle works for you.  If you
  85. are unable to resolve a shareware-related problem with an ASP member by
  86. contacting the member directly, the ASP can probably help you.  The ASP
  87. Ombudsman can help you resolve a dispute or problem with an ASP member, but
  88. does not provide technical support for members' products.  Please write to the
  89. ASP Ombudsman at 545 Grover Road, Muskegon, MI 49442 or send an E-mail message
  90. via CompuServe to ASP Ombudsman 70007,3536.
  91.  
  92. GETTING STARTED
  93.  
  94. The Logic Circuit Analysis program contains over 100 files occupying
  95. approximately 1 MB of disk space and compressed into a single self-extracting
  96. file called "INSTALL.EXE."  This file was created using the LHarc version 2.11
  97. program, which is a copyright reserved freeware program written by Haruyasu
  98. Yoshizaki.
  99.  
  100. To run the program requires an Intel 286 or later microprocessor, an EGA or
  101. VGA graphics adapter with 256 KB of RAM installed, and a color monitor.  It
  102. also requires between 300 KB and 400 KB of available RAM after DOS, drivers
  103. and Terminate and Stay Resident (TSR) program are loaded.  The actual amount
  104. of RAM required depends on the complexity of the circuit.  A minimum of 300 KB
  105. of RAM is required if Expanded Memory (EMS) is installed.  You can use the
  106. CHKDSK or MEM command to detect if you have enough available RAM to run this
  107. program.
  108.  
  109. Logic Circuit Analysis supports a mouse if installed with either the MOUSE.SYS
  110. or MOUSE.COM driver.  However, a mouse is not required.  
  111.  
  112.   The left mouse button is equivalent to the ENTER key and used to
  113.   select items.  
  114.  
  115.   The right mouse button is equivalent to the ESC key and used to exit
  116.   screens.  
  117.  
  118.   If the mouse has three buttons, the middle button is used in the 
  119.   Modify Circuit screen to display the Library of Components screen, and
  120.   to switch pages of library components.
  121.  
  122. To start the Logic Circuit Analysis you must be in the directory containing
  123. this program.  The program is usually stored in the C:\LOGIC11 directory.  Use
  124. the DOS "CD" (Change Directory) command to change the default directory to the
  125. program directory as follows:
  126.  
  127.           CD \LOGIC11 
  128.  
  129. To start the program type "LOGIC" with or without parameters as follows:
  130.  
  131.           LOGIC
  132.              or
  133.           LOGIC filename.LG
  134.              or
  135.           LOGIC filename.LG x
  136.  
  137. The program will display the online tutor when no parameters are after the
  138. "LOGIC" command.  This tutorial contains all the information in this document,
  139. and allows access in a Hyper-Text like fashion.  
  140.  
  141.   The cursor keys (or mouse) can be used to highlight keywords on the
  142.   screen.  
  143.  
  144.   The ENTER key will display another screen of information whose subject
  145.   corresponds to the selected keyword.  
  146.  
  147.   The PGDN key, or selecting the "More" keyword, will display the next
  148.   screen of information.  
  149.  
  150.   The PGUP key will display the previous screen.  
  151.  
  152.   The F1 key will display the first screen of the tutorial.  From the
  153.   first screen the "Table of Contents" keyword will display a screen
  154.   containing the Table of Contents that will allow you to jump directly
  155.   to the desired section.  
  156.  
  157.   The "Index" keyword will display a screen containing many different
  158.   keywords.  
  159.  
  160.   The ESC key will exit the Tutorial and return you to the Logic Circuit
  161.   Analysis program.  
  162.  
  163.   The F5 key will allow you to return to the tutorial at the same screen
  164.   previously displayed.
  165.  
  166.                             Select Sample Circuit Menu
  167.  
  168.   To return to the main menu, press the ESC key.
  169.  
  170.   To display the "Select Sample Circuit" screen, press ENTER.
  171.  
  172.   This screen contains three menus.  
  173.  
  174. From left to right they are the Circuits, Directories, and Drives menus.  Each
  175. menu contains a sorted list of items.  
  176.  
  177.   The LEFT and RIGHT cursor keys move from one menu to another.  
  178.  
  179.   From within a menu you can use the UP and DOWN cursor keys to
  180.   highlight an item.  
  181.  
  182.   The PGUP and PGDN key will page through this directory. 
  183.  
  184.   Alternatively, you can start to type out the entry to highlight the
  185.   desired item. 
  186.  
  187.   Use the ENTER key to select the highlighted item.
  188.  
  189. In the Directories (middle) menu, selecting the ".." item will move you up one
  190. directory in the tree.  Whenever you change the directory, the path displayed
  191. on the second line in blue will change along with the Circuits menu.  In the
  192. Drives menu, you should not select a floppy drive that does not contain a
  193. diskette.  Otherwise, DOS will display an "Abort, Retry, or Fail" menu.  
  194.  
  195.   ESC will exit this menu without selecting a sample circuit.  
  196.  
  197.   At the opening menu you can select "Exit" to exit the program without
  198.   modifying the sample circuit.
  199.  
  200. The program displays the "Modify Circuit" screen when a nonexistent filename
  201. is specified on the command line.  This allows you to create a new circuit. 
  202. By convention, logic circuit files have the extension "LG."  To exit this
  203. screen, press the ESC key.  You can choose to exit with or without saving the
  204. circuit.  If you choose to save the circuit, it will be stored in the file
  205. (filename.LG) specified on the command line when you started the program.  
  206.  
  207. If a problem occurs during the writing of the file, the circuit is written to
  208. the "LOGIC.LG" file.  If the DOS environmental variable TEMP or TMP is
  209. defined, the LOGIC.LG file is written to the directory identified by this
  210. variable, otherwise it is written to the default directory.
  211.  
  212. If the file specified on the command line already exist, the program will
  213. display the opening menu.  Your choices are:
  214.  
  215.           Analyze Circuit
  216.           Modify Circuit
  217.           Select Sample Circuit
  218.           Save Circuit As
  219.           Save Circuit
  220.           Exit
  221.  
  222. If you want to analyze a circuit and exit without modifying the file, add any
  223. character following the filename on the command line as follows:
  224.  
  225.           LOGIC filename.LG x
  226.  
  227. Sample circuit files are in the "LG" subdirectory under the default directory. 
  228. You must prefix sample filenames with "LG\" to use files in this subdirectory
  229. as follows:
  230.  
  231.           LOGIC LG\filename.LG x
  232.  
  233. Let's look at the "NOTANDOR.LG" sample circuit.  Type the following to start
  234. the program:
  235.  
  236.           LOGIC 
  237.  
  238.   To exit the online tutor, press the ESC key.
  239.  
  240.   At the opening menu, press ENTER to select a sample circuit.  
  241.  
  242.   Start typing "NOTANDOR" to highlight this sample circuit.  
  243.  
  244.   Press ENTER to select it from the Circuits menu.  
  245.  
  246. This file actually contains three separate logic circuits.  Each circuit
  247. contains a single logic gate and either a clock or two switches.  The logic
  248. gates from left to right are: NOT, AND, and OR.  
  249.  
  250.   If you press F1 twice, a help screen will identify the different types
  251.   of logic gates.  
  252.  
  253. Notice that TRUE values are in red and FALSE values are in green.  This
  254. convention is consistent with most bread board circuits that use red LEDs
  255. (Light Emitting Diodes) to identify TRUE values.  
  256.  
  257.   Press any key to exit the help screen.
  258.  
  259. When more than one adjustable component (Switch or Clock) is in a circuit:
  260.  
  261.   Use the LEFT and RIGHT cursor keys to select an adjustable component. 
  262.  
  263.   Adjustable components with blue backgrounds show they have been
  264.   selected.  
  265.  
  266.   You can select an adjustable component using a mouse.  
  267.  
  268. Switches are Single-Pole Double-Throw.  
  269.  
  270. When a switch is selected: 
  271.  
  272.   The ENTER key or the left mouse button will toggle the selected
  273.   switch.  
  274.  
  275.   The HOME and UP cursor keys will position the switch in the up or TRUE
  276.   position.  
  277.  
  278.   The END and DOWN cursor keys will position the switch in the down or
  279.   FALSE position.   
  280.  
  281. The clock is an oscillator that automatically toggles between TRUE and FALSE. 
  282. Clocks are typically used with counters.  Computers use clocks to pace the
  283. Central Processing Unit (CPU) as it processes instructions.
  284.  
  285.   Use the "+" (plus) key to speed up the rate at which the screen is
  286.   updated.  
  287.  
  288.   Use the "-" (minus) key to slow the rate.  
  289.  
  290.   The PGDN key will reduce the number of screen updates before the clock
  291.   changes, resulting in a faster clock rate.  
  292.  
  293.   PGUP will do the opposite slowing down the clock.
  294.  
  295. When the clock is selected: 
  296.  
  297.   The ENTER, HOME, END, UP, or DOWN cursor key stop the clock from
  298.   oscillating.  
  299.  
  300.   At this time you can manually toggle the clock with the ENTER key. 
  301.   This mode of operations is usefully for manually stepping a pulse
  302.   through a circuit.  
  303.  
  304.   Press the PGUP or PGDN key to return the clock to automatic
  305.   oscillation.
  306.  
  307. Finally, the "w" key copies the screen into a PC Paintbrush compatible file
  308. called LOGIC.PCX.  
  309.  
  310. If the DOS environmental variable TEMP or TMP is defined, this program writes
  311. the LOGIC.PCX file in the directory identified by this variable, otherwise it
  312. writes to the default directory.
  313.  
  314. Let's look at modifying a circuit.  
  315.  
  316.   Let's start by pressing F6 to modify the circuit.  
  317.  
  318. Now let's modify the first circuit on the left.  Let's replace the clock with
  319. a switch.  The clock is a green circle containing the letter "F" surrounded by
  320. an inverted square pulse.  
  321.  
  322.   Use the cursor keys or the mouse to move the cursor over the clock
  323.   icon.  
  324.  
  325.   Hold the CTRL key and the BACKSPACE key down simultaneously to delete
  326.   this icon.  
  327.  
  328.   Now press F4, or the middle button on the mouse, to display the
  329.   library of components.  If you have a slow disk drive, it may take a
  330.   few seconds to display this screen.  A 256-KB disk cache, such as
  331.   SMARTDRV (see your MS-DOS manual), will speed up the display of this
  332.   screen.  
  333.  
  334.   Use the cursor keys or mouse to move the white box to the icon of the
  335.   switch.  
  336.  
  337.   Press ENTER or the left mouse button to select this icon.  
  338.  
  339. The Modify Circuit screen will now reappear.  
  340.  
  341.   Use the cursor keys or mouse to move the icon to the same location
  342.   where the clock icon was in.
  343.  
  344.   Press ENTER or the left mouse button to lock it in place.  
  345.  
  346. If you attempt to locate the icon too close to an existing icon on the screen,
  347. you will get the message: 
  348.  
  349.                  "ERROR - Component Overlaps Another Component"  
  350.  
  351.   Press any key to clear the message. 
  352.  
  353.   Move the icon to another location.
  354.  
  355.   Press ENTER or the left mouse button to lock it in place.  
  356.  
  357. Icons must have some space between them.  They cannot be touching.  Think of
  358. each icon as having an invisible rectangular outline that encompasses the
  359. icon.  
  360.  
  361. If you need to move an icon: 
  362.  
  363.   Locate the cursor on top of the icon and press the F3 key.  
  364.  
  365.   Use the cursor keys or mouse to move the icon to a new location.
  366.  
  367.   Press ENTER or the left mouse button to lock it in place.
  368.  
  369. We now must connect the switch to the NOT gate.  
  370.  
  371.   Locate the cursor over the right circle (connection) of the switch,
  372.   and press ENTER or the left mouse button.  The icon will turn orange. 
  373.  
  374.   Now locate the cursor over the left portion of the NOT gate and press
  375.   ENTER or the left mouse button.  The program will draw a connection
  376.   (line) between the two connection points.  
  377.  
  378. You must always select a node (interconnect, fixed, switch, or clock) before
  379. selecting a logic gate (or IC) to make a connection.  You can use the same
  380. procedure to remove a connection.  You can connect two nodes in any order.
  381.  
  382.   You can press F1 for a brief help message.  
  383.  
  384.   For additional help, press F1 a second time to receive a full screen
  385.   of help.  This screen identifies the different types of nodes and
  386.   logic gates in the library.  
  387.  
  388.   Press any key to exit help.
  389.  
  390.   Finally, press F6 to start the "Analyze Circuit" screen and see the
  391.   results of your modification.  
  392.  
  393. Do not save the modified circuit!
  394.  
  395. LOGIC
  396.  
  397. There are only two logical values: "TRUE" and "FALSE."  There are three
  398. fundamental logical operators from which all other logical operators.  They
  399. are "NOT," "AND," and "OR."   
  400.  
  401. The NOT operator works as follows:  If it is NOT TRUE, it must be FALSE. 
  402. Conversely, if it is NOT FALSE, it must be TRUE.  
  403.  
  404. All of the inputs must be TRUE for the AND operator to be TRUE.  
  405.  
  406. Any of the inputs can be TRUE for the OR operator to be TRUE.  In other words,
  407. all the inputs must be FALSE for the OR operator to be FALSE.  
  408.  
  409. The following table summarizes these fundamental logical operators:
  410.  
  411.  
  412.                   ╔═══════════════╦═══════════════════════════╗
  413.                   ║     Input     ║          Output           ║
  414.                   ╟───────┬───────╫────────┬─────────┬────────╢
  415.                   ║   A   │   B   ║ NOT A  │ A AND B │ A OR B ║
  416.                   ╠═══════╪═══════╬════════╪═════════╪════════╣
  417.                   ║ FALSE │ FALSE ║ TRUE   │  FALSE  │  FALSE ║
  418.                   ║ FALSE │ TRUE  ║ TRUE   │  FALSE  │  TRUE  ║
  419.                   ║ TRUE  │ FALSE ║ FALSE  │  FALSE  │  TRUE  ║
  420.                   ║ TRUE  │ TRUE  ║ FALSE  │  TRUE   │  TRUE  ║
  421.                   ╚═══════╧═══════╩════════╧═════════╧════════╝
  422.  
  423. Let's take another look at the "NOTANDOR.LG" sample circuit.  
  424.  
  425. The triangular icon on the left is a NOT operator.  This icon looks like a
  426. triangle pointing to the right followed by a circle.  The circle represents
  427. the NOT operator and the triangle represents a driver.   The circle will
  428. always be the opposite color (red vs. green) of the triangle showing that the
  429. logic value has changed.
  430.  
  431. The AND gate is in the middle and the OR gate is on the right.  
  432.  
  433. Besides the fundamental logical operators, there are three additional logical
  434. operators that are commonly used and derived from the three fundamental
  435. operators.  They are "NAND," "NOR," and Exclusive OR "XOR."  
  436.  
  437. The NAND operator is the same as "NOT AND."  In other words, the NOT operator
  438. inverts the results of the AND operator.   The following logical equation
  439. defines the NAND operator: 
  440.  
  441.           A NAND B = NOT (A AND B)
  442.  
  443. The "NANDNOR.LG" sample circuit depicts the NAND logic gate as an AND gate
  444. followed by a NOT gate on the left portion of the screen.  Below it is the
  445. icon for the NAND logic gate that looks like the AND gate followed by a circle
  446. in the opposite color.
  447.  
  448. Similarly, the NOR operator is the same as "NOT OR" and defined by the
  449. following logical equation:
  450.  
  451.           A NOR B = NOT (A OR B)
  452.  
  453. The "NANDNOR.LG" sample circuit depicts the NOR gate as an OR gate followed by
  454. a NOT gate on the right portion of the screen.  Below it is the icon for the
  455. NOR logic gate that looks like the OR gate followed by a circle in the
  456. opposite color.
  457.  
  458. The Exclusive OR is similar to the OR operator, except it can only support two
  459. inputs.  Only one input can be TRUE at a time for the answer to be TRUE.  In
  460. other words, the answer is TRUE if one or the other input is TRUE, but not
  461. both.  The logical equations for Exclusive OR (XOR) are the following:
  462.  
  463.           A XOR B = (A OR B) AND NOT (A AND B)
  464.                           or
  465.           A XOR B = (A OR B) AND (A NAND B)
  466.  
  467. The "XOR.LG" sample circuit depicts the logic circuit for the Exclusive OR
  468. gate, and below it is the icon for the XOR gate.  Note the XOR icon is gray
  469. instead of red or green.  The gray color shows this icon represents an
  470. Integrated Circuit (IC) instead of a basic logic gate.  This IC contains the
  471. logic circuit displayed above.
  472.  
  473. The following table summarizes the NAND, NOR, and XOR logical operators:
  474.  
  475.                 ╔═══════════════╦═══════════════════════════════╗
  476.                 ║     Input     ║             Output            ║
  477.                 ╟───────┬───────╫───────────┬─────────┬─────────╢
  478.                 ║   A   │   B   ║ A NAND B  │ A NOR B │ A XOR B ║
  479.                 ╠═══════╪═══════╬═══════════╪═════════╪═════════╣
  480.                 ║ FALSE │ FALSE ║   TRUE    │  TRUE   │  FALSE  ║
  481.                 ║ FALSE │ TRUE  ║   TRUE    │  FALSE  │  TRUE   ║
  482.                 ║ TRUE  │ FALSE ║   TRUE    │  FALSE  │  TRUE   ║
  483.                 ║ TRUE  │ TRUE  ║   FALSE   │  FALSE  │  FALSE  ║
  484.                 ╚═══════╧═══════╩═══════════╧═════════╧═════════╝
  485.  
  486. DEMORGAN's THEOREM
  487.  
  488. I will now discuss the DeMorgan's theorem.  This theorem states: "That if you
  489. invert the input and output of the AND operator, you obtain the same results
  490. as the OR operator.  Conversely, if you invert the input and output of the OR
  491. operator, you obtain the same results as the AND operator."  
  492.  
  493. The sample circuit "DEMORGAN.LG" depicts the equivalent AND operator using an
  494. OR operator with three NOT operators in the circuit on the left.  The circuit
  495. on the right depicts the OR operator using an AND operator and three NOT
  496. operators.
  497.  
  498. Also, there are several corollaries to this theorem.  Listed below are the
  499. logical equations for this theorem and its corollaries:
  500.  
  501.            A AND B = NOT ( (NOT A) OR (NOT B) )
  502.            A AND B = (NOT A) NOR (NOT B)
  503.             A OR B = NOT ( (NOT A) AND (NOT B) )
  504.             A OR B = (NOT A) NAND (NOT B)
  505.           A NAND B = (NOT A) OR (NOT B)
  506.            A NOR B = (NOT A) AND (NOT B)
  507.  
  508. The DeMorgan's theorem can be extremely useful for reducing the total number
  509. of logic gates within a circuit when you have extra gates, but they are the
  510. wrong type.
  511.  
  512. It is possible to derive the three fundamental logical operators, NOT, AND,
  513. and OR using a single logical operator, and subsequently derive all logical
  514. operators from this single logical operator.  (The original computer designers
  515. only had one or two logical operator circuits to work with).  This logical
  516. operator can be either an NAND or a NOR logical operator.  
  517.  
  518. The "NANDLOGC.LG" sample circuit uses the NAND logical operator to function as
  519. the other logical operators.  The following equations also illustrate this
  520. capability:
  521.  
  522.              NOT A = A NAND A
  523.            A AND B = NOT (A NAND B)
  524.             A OR B = (NOT A) NAND (NOT B)
  525.            A NOR B = NOT ( (NOT A) NAND (NOT B) )
  526.            A XOR B = NOT ( (NOT A) NAND (NOT B) NAND (A NAND B) )
  527.            A XOR B = ( A NAND (A NAND B) ) NAND ( B NAND (A NAND B) )
  528.  
  529. The NAND equivalent circuit is on top and the corresponding logic operator is
  530. below each circuit.  The top left circuit represented the NOT logical
  531. operator, followed by the AND, and OR logic gates on the left side of the
  532. screen.  On the top of the right side of the screen are the NOR operator and
  533. the Exclusive OR operator below it.
  534.  
  535. The "NORLOGIC.LG" sample circuit uses the NOR logical operator to function as
  536. the other logical operators.   The following equations also illustrate this
  537. capability:
  538.  
  539.              NOT A = A NOR A
  540.            A AND B = (NOT A) NOR (NOT B)
  541.             A OR B = NOT (A NOR B)
  542.           A NAND B = NOT ( (NOT A) NAND (NOT B) )
  543.            A XOR B = (A NOR B) NOR ( (NOT A) NOR (NOT B) )
  544.  
  545. The NOR equivalent circuit is on top and the corresponding logic operator is
  546. below each circuit similar to the "NANDLOGC.LG" sample circuit.
  547. CALCULATION METHOD
  548.  
  549. "Logic Gates" are circuits that do logical operations.  The Logic Circuit
  550. Analysis program supports four fundamental logic gates and a 3-State logic
  551. gate.  The four fundamental logic gates are AND, OR, NAND, and NOR.  Each
  552. fundamental logic gate can have between one and four inputs.  A one input NOR
  553. gate represents the NOT logic gate in this program.  (A one input NAND gate
  554. could have represented the NOT logic gate).
  555.  
  556. All the inputs for the AND gate must be TRUE for the result to be TRUE.
  557.  
  558. All the inputs for the OR gate must be FALSE for the result to be FALSE.
  559.  
  560. All the inputs for the NAND gate must be TRUE for the result to be FALSE.
  561.  
  562. All the inputs for the NOR gate must be FALSE for the result to be TRUE.
  563.  
  564.  
  565.  
  566. The 3-State device can have three possible results: TRUE, FALSE, and OFF. 
  567.  
  568. When the bottom input is FALSE, the output (right) is ON and set to the input.
  569.  
  570. When the bottom input is TRUE, the output is OFF (neither TRUE nor FALSE).  
  571.  
  572. Computers use 3-State devices to connect multiple circuits to a bus. Only one
  573. 3-State device can be active at once.  The "3STATE.LG" sample circuit
  574. illustrates the use of 3-State devices.  For this example, the input is preset
  575. to TRUE for the top gate and FALSE for the bottom gate.  (Instead of
  576. presetting the input, switches or logic gates could be the input.)  The two
  577. 3-State devices have their outputs joined as would occur on a bus.  If both
  578. devices are OFF (switches set to TRUE), the output is OFF and colored gray. 
  579. Otherwise, the output color corresponds to the device that is ON.  Both
  580. 3-State devices should never be ON (both switches set to TRUE) simultaneously!
  581.  
  582. When an input is connected to a 3-state logic gate that is OFF, the input is
  583. treated as TRUE.  This is consistent with TTL type logic gates.  Inputs should
  584. never be left unconnected.
  585.  
  586. The Logic Circuit Analysis program updates all the connections, then evaluates
  587. all the logic gates.  Next the screen displays the results and the program
  588. waits some amount of time before starting all over.  In this manner each logic
  589. gate takes the same amount of time.  The "+" and "-" key adjusts the delay
  590. between screen updates speeding and slowing the screen updates.  Initially,
  591. the clock will change value every eight screen updates.  The PGUP and PGDN key
  592. is used to adjust the number of screen updates for the clock to change value.
  593.  
  594. Electrically a clock is an oscillator.  It is possible using logic gates to
  595. create a clock, as illustrated in the "CLOCK.LG" sample circuit.  This circuit
  596. uses three NOT gates in series.  (You may want to slow the display using the
  597. minus key).
  598.  
  599. The program can support up to 1,000 logic gates, 3,000 nodes, and 7,000
  600. connections with a maximum of eight connections per node.  The 1,000 logic
  601. gates include logic gates embedded within ICs in the library and count the IC
  602. icon as well.  If you press the F1 key when analyzing a circuit, the program
  603. will identify how many logic gates, nodes, and connections are in the circuit
  604. under evaluation.  Press any key to resume the analysis.
  605.  
  606. If you would like to learn how to build an electronic circuit to function as a
  607. logic gate, I recommend you invest in my "DC Circuit Analysis" program.  This
  608. program will teach you about logic circuits made from Diodes, Diode-Transistor
  609. Logic (DTL), Transistor-Transistor Logic (TTL), Emitter-Coupler Logic (ECL),
  610. and Complementary Metal Oxide Semiconductor (CMOS) electronic circuits.
  611.  
  612. ENCODERS and DECODERS
  613.  
  614. Let's start by looking at encoders and decoders.  A decoder takes a binary
  615. number and decodes it into one of N lines, where N is the number of different
  616. values the binary number can take on.  As an example, a 2-bit binary number
  617. decodes into four lines, since there are four possible values (0, 1, 2, and
  618. 3).
  619.  
  620. An encoder is the opposite of a decoder.  It will take N lines and encode them
  621. into a binary number, depending on the line that is active.  Since more then
  622. one input line can be active at a time, a priority is established giving
  623. preference to lines that correspond to larger binary values over lines
  624. corresponding to smaller binary values.
  625.  
  626. Let's look at a 2-bit to 4-line decoder as illustrated in the "2TO4.LG" sample
  627. circuit.  Notice that the two binary input lines each connect to a NOT gate
  628. creating four input lines (two normal, and two inverted).  The four NAND
  629. operators form the four possible output combinations.  Each NAND gate
  630. corresponds to one output line.  That output is only active when it is FALSE.
  631.  
  632. The logical equations for the 2-bit to 4-line decoder follow, where A is the
  633. most significant input and B is the least significant input:
  634.  
  635.                    Output 00 (0) = NOT ( (NOT A) AND (NOT B) )
  636.                    Output 01 (1) = NOT ( (NOT A) AND      B  )
  637.                    Output 10 (2) = NOT (      A  AND (NOT B) )
  638.                    Output 11 (3) = NOT (      A  AND      B  )
  639.  
  640. As you toggle the two input switches, you will observe that only one line at a
  641. time will be FALSE, the other three will be TRUE.  The FALSE line is the
  642. selected line.  Binary 00 (both switches set to FALSE) corresponds to the
  643. bottom line, and binary 11 (both switches set to TRUE) corresponds to the top
  644. line.
  645.  
  646. Similarly, the sample circuit "3TO8.LG" illustrates the 3-bit to 8-line
  647. decoder circuit.  There are one additional input bit and four additional
  648. output lines.
  649.  
  650. The logical equations for the 3-bit to 8-line decoder follow, where A is the
  651. most significant input and C is the least significant input:
  652.  
  653.              Output 000 (0) = NOT ( (NOT A) AND (NOT B) AND (NOT C) )
  654.              Output 001 (1) = NOT ( (NOT A) AND (NOT B) AND      C  )
  655.              Output 010 (2) = NOT ( (NOT A) AND      B  AND (NOT C) )
  656.              Output 011 (3) = NOT ( (NOT A) AND      B  AND      C  )
  657.              Output 100 (4) = NOT (      A  AND (NOT B) AND (NOT C) )
  658.              Output 101 (5) = NOT (      A  AND (NOT B) AND      C  )
  659.              Output 110 (6) = NOT (      A  AND      B  AND (NOT C) )
  660.              Output 111 (7) = NOT (      A  AND      B  AND      C  )
  661.  
  662. Now that we can decode a binary number into individual lines, the next type of
  663. circuit encodes four lines into a 2-bit binary number.  Other encoders are
  664. also possible.
  665.  
  666. The sample circuit "4TO2.LG" illustrates a 4-line to 2-bit encoder.  This
  667. circuit could be used with a four-button keypad to decide which button was
  668. pressed and encode it into a 2-bit binary value.  The four switches on the
  669. left represent the keypad.  The top output on the right represents the most
  670. significant bit, and the middle output represents the least significant bit. 
  671. A button is pressed when a switch is set to FALSE or "0."  When the lower
  672. output on the right is FALSE or "0," it shows a button has been pressed.  If
  673. more than one button is pressed (set to FALSE), the encoder will respond as
  674. though the most significant (upper) switch was pressed.  
  675.  
  676. The following table illustrates this circuit's response, where "?" on the
  677. input shows either "0" or "1", "MSB" on the output shows the most significant
  678. output bit, "LSB" shows the least significant output bit, and "P" shows that a
  679. key was pressed.
  680.  
  681.                      ╔═══════════════════╦══════════════════╗
  682.                      ║       Input       ║      Output      ║
  683.                      ╟────┬────┬────┬────╫──────┬─────┬─────╢
  684.                      ║ B0 │ B1 │ B2 │ B3 ║   P  │ MSB │ LSB ║
  685.                      ╠════╪════╪════╪════╬══════╪═════╪═════╣
  686.                      ║  1 │  1 │  1 │  1 ║   1  │  0  │  0  ║
  687.                      ║  0 │  1 │  1 │  1 ║   0  │  0  │  0  ║
  688.                      ║  ? │  0 │  1 │  1 ║   0  │  0  │  1  ║
  689.                      ║  ? │  ? │  0 │  1 ║   0  │  1  │  0  ║
  690.                      ║  ? │  ? │  ? │  0 ║   0  │  1  │  1  ║
  691.                      ╚════╧════╧════╧════╩══════╧═════╧═════╝
  692.     
  693. The logical equations for the 4-line to 2-bit encoder are as follows:
  694.  
  695.           MSB = B3 NAND B2
  696.           LSB = (NOT B3) OR (B2 AND (NOT B1))
  697.             P = B0 AND B1 AND B2 AND B3
  698.  
  699. MSB is set if either button B2 or B3 is pressed (FALSE).  LSB is set if either
  700. button B3 or B1 is pressed but not B2.
  701.  
  702. SELECTORS
  703.  
  704. The next family of circuits I will discuss is the selectors.  The selector
  705. uses a binary value to select one of N data input lines.  The value of the
  706. binary input decides which data input line will be selected for output. 
  707.  
  708. The sample circuit "1OF2.LG" illustrates a 1 of 2-line selector with two data
  709. inputs and one selector input.  The selector switch decides which of the two
  710. data inputs will be selected for output.  In this example, both data inputs
  711. are set to TRUE to make it easier to track which input is reaching the output. 
  712. The input on top is active when the switch is set to TRUE.  The input on
  713. bottom is active when the switch is set to FALSE.  The following logic
  714. equation corresponds to this sample circuit:
  715.  
  716.                     Output = ( I0 AND (NOT S) ) OR ( I1 AND S)
  717.  
  718. where: S is the selector switch, I0 and I1 are the input lines.
  719.  
  720. The next sample circuit "1OF4.LG" illustrates a 1 of 4-line selector with four
  721. data inputs and a 2-bit selector.  The 2-bit selector decides which of the
  722. four data inputs will be selected for output.  In this example, all the data
  723. inputs are set to TRUE to make it easier to track which input is reaching the
  724. output.  The top switch is the most significant binary input bit, and the
  725. bottom switch is the least significant binary input bit.  The following logic
  726. equation corresponds to this sample circuit:
  727.  
  728.                     Output = ( I0 AND (NOT S0) AND (NOT S1) )
  729.                                         OR
  730.                              ( I1 AND      S0  AND (NOT S1) )
  731.                                         OR
  732.                              ( I2 AND (NOT S0) AND      S1  )
  733.                                         OR
  734.                              ( I3 AND      S0  AND      S1  )
  735.  
  736. where: I0, I1, I2, and I3 are the data input, 
  737.        and S0 and S1 are the binary select input.
  738.  
  739. CROSS BAR SWITCHES
  740.  
  741. A telephone company can use cross bar switches to route phone calls within a
  742. telephone exchange.  Each phone call is converted from an analog signal
  743. (varying voltages) to digital data (binary number representing the amplitude
  744. of the voltage).  The digital data passes through the system serially (one bit
  745. at a time).  Each telephone conversation is transmitted at 56 Kbps (a thousand
  746. bits per second).  Consequently, only one wire per telephone is required to
  747. transmit the conversation. (A second wire is required to receive the
  748. conversation of the other party, and a third wire that is electrically
  749. connected to ground).
  750.  
  751. Cross bar switches get their name from the simplest switch element that
  752. consists of two data inputs, two data outputs, and one selector input with two
  753. states.  In the first state both inputs pass straight through to the output. 
  754. In other words, the top input connects to the top output, and the bottom input
  755. connects to the bottom output.  In the second state the two inputs cross over,
  756. such that the top input connects to the bottom output, and the bottom input
  757. connects to the top output.
  758.  
  759. The simplest cross bar switch consists of two "1 of 2-line selectors" as
  760. illustrated in the "2XBAR.LG" sample circuit.  In this example, the top input
  761. is preset to TRUE and the bottom input is preset to FALSE to make it easier to
  762. follow the logic.  The switch represents the selector input.  When the switch
  763. is set to FALSE, the two input lines pass straight through to the output. 
  764. When the switch is set to TRUE, the two input lines cross over such that the
  765. top input connects to the bottom output, and the bottom input connects to the
  766. top output.
  767.  
  768. A 2-input cross bar switch is not very practical by itself.  However, it can
  769. be used as a building block to construct a larger cross bar switch matrix. 
  770. The "4XBAR.LG" sample circuit illustrates a 4-input cross bar switch
  771. consisting of six 2-input cross bar switch elements arranged in three columns
  772. of two 2-input switch elements.  Each output of the 2-input cross bar switch
  773. elements must connect to a different 2-input cross bar switch element in the
  774. next stage (column).  The middle stage, the second column of switches, is
  775. required to support all the possible paths through the switch.  Without a
  776. second stage, both inputs on the top cannot be transferred to the two outputs
  777. on the bottom.  Every other input is preset to TRUE and the remaining inputs
  778. are preset to FALSE to make it easier to follow the logic through this
  779. circuit.  Note: when all the selector switches are set to FALSE, the input
  780. passes straight through to the corresponding output.
  781.  
  782. There are six selector inputs in a 4-input cross bar switch.  In other words,
  783. there are 64 (2**6) possible combinations of paths the input can take to reach
  784. the output in the switch.  This also means that there is more than one path a
  785. single input can take through the switch to reach the same output line.
  786.  
  787. In practice, a computer controls the selector inputs and establishes which
  788. path a telephone conversation will take through the cross bar switch.  When
  789. you dial another person's phone number, the computer decides which switches
  790. you will traverse and sets the selector inputs appropriately.  This also means
  791. that any existing phone calls may be rerouted at this time to accommodate your
  792. phone call.  On the average, a phone call takes a different path through the
  793. switch matrix every 20 seconds.
  794.  
  795. More complex cross bar switches can be constructed from the 4-input cross
  796. switch element.  The "16XBAR.LG" sample circuit illustrates a 16-input cross
  797. bar switch.  It requires three stages (columns of switches), each consisting
  798. of four 4-input cross bar switches.  There is a total of twelve 4-input
  799. switches and 72 selector inputs in a 16-input cross bar switch.  Since it is
  800. impractical to connect 72 switches to the selector inputs, this sample circuit
  801. only illustrates the interconnections between each stage.  Each output of the
  802. 4-input cross bar switch elements must connect to a different 4-input cross
  803. bar switch element in the next stage (column).  The middle stage, second the
  804. column of switches, is required to support all the possible paths through the
  805. switch.  Without a second stage, all four inputs on the top cannot be
  806. transferred to the four outputs on the bottom.  Every other input is preset to
  807. TRUE and the remaining inputs are preset to FALSE to make it easier to follow
  808. the logic through this circuit.  Note: this is the most complex sample circuit
  809. in this program.  If you press F1 while in the Analyze Circuit screen, it will
  810. identify the total number of logic gates, nodes, and connections in this
  811. circuit.  The total includes all the logic gates, nodes, and connections in
  812. each of the integrated circuit components (e.g., 4-input cross bar switch
  813. elements that in turn are constructed of 2-input cross bar switch elements).
  814.  
  815. This concludes the discussion on cross bar switches.
  816.  
  817. LATCHES 
  818.  
  819. How does computer memory work?  
  820.  
  821. The basis for all computer memory is the Set-Reset (S-R) Latch, which consists
  822. of two NAND gates that are cross connected.  The sample circuit "SRLATCH.LG"
  823. illustrates the Set-Reset Latch.  This circuit has two inputs and two outputs. 
  824. The output of the top NAND gate is the normal output, and the output of the
  825. bottom NAND gate is the inverted output.  The top switch Sets the latch to
  826. TRUE, when it is in the FALSE position.  The bottom switch Resets the latch to
  827. FALSE, when it is in the FALSE position.  When both switches are in the TRUE
  828. position, the circuit "remembers" its last setting.  However, both switches
  829. should not be in the FALSE position, since both outputs (which are supposed to
  830. be opposites of each other) will both become TRUE.
  831.  
  832. The next sample circuit we will look at is "SRLATCHE.LG," which contains a
  833. Set-Reset Latch with Enable.  This circuit consists of four NAND gates, where
  834. the two on the right are the same Set-Reset latches discussed above, and the
  835. two NAND gates on the left are used to implement the Enable function.  The
  836. switch in the middle is the Enable input that must be TRUE before either the
  837. Set or Reset switch will take effect.  When the Enable switch is FALSE, the
  838. circuit remembers its last setting.  Initially, this circuit will oscillate. 
  839. The oscillation is due to the unknown initial state at power up.  (Most real
  840. circuits have a power on reset to prevent oscillation).  You must set the
  841. Enable switch to TRUE, and either the Set or Reset switch TRUE to stop the
  842. oscillation and establish a known state.  The switch on the top is the Set
  843. input, and works opposite of the Set discussed in the previous circuit.  When
  844. Set is TRUE, the Latch will be set to TRUE.  Similarly, when the Reset switch
  845. is TRUE, the latch will be set to FALSE.  When both Set and Reset switches are
  846. set to FALSE, the circuit remembers the last setting.
  847.  
  848. The Data Latch is an improvement on the Set-Reset Latch.  The "DLATCH.LG"
  849. sample circuit illustrates the Data Latch.  This circuit consists of four NAND
  850. gates, where the two NAND gates on the right form the familiar Set-Reset Latch
  851. described above.  The top switch is the Data input, and the bottom switch is
  852. the Enable input.  When the Enable switch is TRUE, the Data input is stored in
  853. the latch.  When the Enable switch is FALSE, the Data input is ignored, and
  854. the circuit remembers its last setting.  Initially, this circuit will
  855. oscillate.  You must set the Enable switch TRUE to stop the oscillation.
  856.  
  857. FLIP-FLOPS
  858.  
  859. The next type of logic circuit I will discuss is the Master-Slave Flip-Flop. 
  860. A Flip-Flop consists of two latches connected in series.  Flip-Flops are used
  861. to create registers, shift registers, and counters which are discussed in a
  862. later section.
  863.  
  864. The Set-Reset Flip-Flop is an example of a Master-Slave Flip-Flop.  It
  865. consists of two latches connected in series and illustrated in the "SRFF.LG"
  866. sample circuit.  Both latches are Set-Reset Latches with Enable as described
  867. above.  When the Enable input is TRUE, the value of the first (Master) latch
  868. is Set or Reset as described above.  When the Enable input is FALSE, the value
  869. stored in the first latch transfers to the second (Slave) latch.  Initially,
  870. this circuit will oscillate.  You must set either the Set or Reset switch to
  871. TRUE and toggle the Enable switch to TRUE and back to FALSE to stop the
  872. oscillation.
  873.  
  874. The sample circuit "SRFFSC.LG" depicts a Set-Reset Flip-Flop with Preset and
  875. Clear inputs.  This Flip-Flop is similar to the previously discussed Set-Reset
  876. Flip-Flop, except it has additional inputs called "Preset" and "Clear."  The
  877. Preset input is the switch on top and the Clear input is the switch on the
  878. bottom.  These additional inputs eliminate the initial oscillation and allow
  879. this Flip-Flop to initialize to either a TRUE or a FALSE value.  When the Set
  880. input is FALSE, both latches in the Flip-Flop are set TRUE.  When the Clear
  881. input is FALSE, both latches are set to FALSE.  If both Preset and Clear are
  882. FALSE, both outputs are set TRUE, similar to when the original Set-Reset Latch
  883. had both Set and Reset inputs set to FALSE.
  884.  
  885. The Data Flip-Flop is another example of a Master-Slave Flip-Flop.  It
  886. consists of two latches connected in series as illustrated in the "DFF.LG"
  887. sample circuit.  The first (Master) latch is a Data Latch and the second
  888. (Slave) latch is a Set-Reset Latch with Enable.  When the Enable input is
  889. TRUE, the value of the Data input transfers to the first latch.  When the
  890. Enable input is FALSE, the value stored in the first latch transfers to the
  891. second latch.  Initially, this circuit will also oscillate.  You must toggle
  892. the Enable switch to TRUE and back to FALSE to stop the oscillation.
  893.  
  894. The sample circuit "DFFSC.LG" depicts a Data Flip-Flop with Preset and Clear
  895. inputs.  This Flip-Flop is similar to the previously discussed Data Flip-Flop,
  896. except it has additional inputs called "Preset" and "Clear."  The Preset input
  897. is the switch on top and the Clear input is the switch on the bottom.  These
  898. additional inputs eliminate the initial oscillation and allow this Flip-Flop
  899. to initialize to either a TRUE or a FALSE value.  When the Preset input is
  900. FALSE, both latches in the Flip-Flop are set TRUE.  When the Clear input is
  901. FALSE, both latches are set to FALSE.  If both Preset and Clear are FALSE,
  902. both outputs are set TRUE, similar to when the original Set-Reset Latch had
  903. both Set and Reset inputs set to FALSE.
  904.  
  905. The "J-K" Flip-Flop or the Toggle Flip-Flop is the last type of Flip-Flop I
  906. will discuss.  The J-K Flip-Flop is identical to the Set-Reset Flip-Flop with
  907. Preset and Clear, except the output of the Slave latch is cross connected to
  908. the input of the Master latch, forcing it to toggle when a clock is connected
  909. to the Enable input.  The sample circuit "JKFFSC.LG" illustrates the J-K Flip-
  910. Flop with Preset and Clear.  The "J" input corresponds to the "Set" input and
  911. the "K" input corresponds to the "Reset" input.  For this Flip-Flop to toggle,
  912. all the inputs (J, K, Preset, and Clear) must be TRUE.  When the Preset input
  913. is FALSE, both latches in the Flip-Flop are set TRUE.  When the Clear input is
  914. FALSE, both latches are set to FALSE.  If both Preset and Clear are FALSE,
  915. outputs on both latches are set TRUE, similar to when the original Set-Reset
  916. Latch had both Set and Reset inputs set to FALSE.
  917. REGISTERS
  918.  
  919. Registers, shift registers and counters are constructed from Flip-Flops.
  920.  
  921. The simplest use of Flip-Flops is a register.  A register is memory used
  922. within a Central Processing Unit (CPU) to temporarily hold information.  A
  923. 4-bit register consists of four Data Flip-Flops as illustrated in the sample
  924. circuit "REGISTER.LG."  In this example, the input data is preset to TRUE,
  925. FALSE, TRUE, and FALSE.  The Clear switch is on the bottom.  When the Clear
  926. switch is FALSE, all the Flip-Flops reset to FALSE.  The other switch on the
  927. left is the Enable switch.  When the Enable switch is TRUE, input data
  928. transfers to the output of the Flip-Flop.
  929.  
  930. The next use of Flip-Flops we will explore is the Shift Register.  Shift
  931. Registers can take serial input data (one bit at a time) and output parallel
  932. data.  They can also take parallel input data (four or more bits at once) and
  933. output serial data.  An example of serial data is using the COM1: port to
  934. communicate with another computer via a modem.  An example of parallel data is
  935. using the LPT1: port to communicate with a printer.
  936.  
  937. The Shift register consists of multiple Data Flip-Flops connected in series,
  938. requiring one Flip-Flop for each bit in parallel.  The Serial input enters the
  939. left Flip-Flop and the Serial output exits the right Flip-Flop.  The parallel
  940. output is simply reading the output of each Flip-Flop simultaneously.
  941.  
  942. The first shift register we will look at converts Serial input to Parallel
  943. Output.  The sample circuit "SPSHREG.LG" illustrates a Shift Register.  The
  944. top switch represents the serial input and the bottom switch is the Clear
  945. input.  When the Clear switch is FALSE, the shift register resets.  When it is
  946. TRUE, data will shift through the Flip-Flops from left to right with each
  947. clock pulse.  Note that the Preset ("s") input on each Flip-Flop is not used. 
  948. By default it is assumed to be TRUE.  The parallel output is always available
  949. by reading the output (Q) of each Flip-Flop.
  950.  
  951. The next circuit we will look at is a parallel to serial Shift Register as
  952. illustrated in the "SHIFTREG.LG."  It also uses Data Flip-Flops, but has the
  953. added ability to load data in parallel.  In reality, this arrangement can be
  954. used to convert serial to parallel as well as parallel to serial.  A pair of
  955. AND gates and one OR gate are used to decide if data should be loaded or the
  956. value of the previous Flip-Flop should be loaded in to the next Flip-Flop in
  957. series.  The switch at the very top loads data when it is FALSE, or count when
  958. it is TRUE.  The switch at the bottom is the Clear input and it must be TRUE
  959. to count, or FALSE to reset all the Flip-Flops.  The switch in the middle
  960. represents the serial input data.  In this example the parallel input data is
  961. fixed using the following values (TRUE, FALSE, TRUE, FALSE).
  962.  
  963. BINARY NUMBERS
  964.  
  965. Before we can discuss counters, we must discuss binary numbers.  A digital
  966. computer is a "Binary" computer.  Binary computers deal with only two states:
  967. TRUE or FALSE, 1 or 0, On or Off, Voltage or Ground.  Binary computers do not
  968. use varying voltages to represent values, instead they use simple On/Off
  969. circuits.  The binary value 1 corresponds to TRUE, and the binary value 0
  970. corresponds to FALSE.
  971.  
  972. The decimal numbering system, which we are familiar with, uses ten different
  973. digits (0 through 9), and is called base 10.  A binary computer represents
  974. numbers using base 2, which only has two digits "0" and "1."  In base 10, the
  975. least significant (right most) digit is multiplied by 1 (10**0), the next
  976. digit by 10 (10**1), 100 (10**2), 1000 (10**3), etc.  In base 2, the least
  977. significant digit is multiplied by 1 (2**0), the next by 2 (2**1), 4 (2**2), 8
  978. (2**3), etc.  So the decimal number 9 can be represented by the binary number
  979. 1001.  The following table depicts the first sixteen (starting with zero)
  980. binary and decimal numbers:
  981.  
  982.                                ╔════════╤═════════╗
  983.                                ║ Binary │ Decimal ║
  984.                                ╟────────┼─────────╢
  985.                                ║  0000  │    0    ║
  986.                                ║  0001  │    1    ║
  987.                                ║  0010  │    2    ║
  988.                                ║  0011  │    3    ║
  989.                                ║  0100  │    4    ║
  990.                                ║  0101  │    5    ║
  991.                                ║  0110  │    6    ║
  992.                                ║  0111  │    7    ║
  993.                                ║  1000  │    8    ║
  994.                                ║  1001  │    9    ║
  995.                                ║  1010  │   10    ║
  996.                                ║  1011  │   11    ║
  997.                                ║  1100  │   12    ║
  998.                                ║  1101  │   13    ║
  999.                                ║  1110  │   14    ║
  1000.                                ║  1111  │   15    ║
  1001.                                ╚════════╧═════════╝
  1002.  
  1003. A binary digit is called a "bit."  So far we only discussed 4-bit (four binary
  1004. digits) binary numbers.  Computers can handle larger numbers, such as 8-bit (0
  1005. through 255), 16-bit (0 through 65,535), and 32-bit (0 through 4,294,967,295). 
  1006. The largest value is calculated by raising 2 to the power of N and subtracting
  1007. one from this value, where N is the number of binary digits (bits) used to
  1008. represent the number.  We will concentrate on the 4-bit numbers.
  1009.  
  1010. COUNTERS
  1011.  
  1012. The next subject I will discuss is Counters.  They use J-K Flip-Flops that
  1013. toggle in response to a clock pulse.  The output of each Flip-Flop is half the
  1014. frequency of the input clock rate.  By connecting the J-K Flip-Flops in
  1015. series, we can form counters, one Flip-Flop for each bit in the counter.  The
  1016. least significant bit is on the left and the most significant bit is on the
  1017. right, which is opposite of the way binary numbers are written.
  1018.  
  1019. The first counter we will look at is a 4-bit Asynchronous counter.  It is
  1020. Asynchronous because the change of each Flip-Flops ripples through the counter
  1021. from left to right, instead of occurring simultaneously.  The sample circuit
  1022. "COUNTER.LG" illustrates this counter.  
  1023.  
  1024.   When the switch is in the FALSE position, the counter is cleared and
  1025.   not counting.  When the switch is TRUE, the counter will count from 0
  1026.   to 1111 (15).  
  1027.  
  1028.   There are four output bits, corresponding to the normal output labeled
  1029.   "Q" in the upper right-hand corner of each Flip-Flop.  
  1030.  
  1031.   You may find it easier to put the clock in manual mode and use the
  1032.   ENTER key to step though counting sequence.  Use the PGUP or PGDN key
  1033.   to return the clock to automatic mode.
  1034.  
  1035. Notice: the J, K, and Set inputs are not connected to anything.  They are
  1036. treated as TRUE by this program.  In a real circuit, you should explicitly
  1037. connect them to a TRUE source, and not leave them unconnected.
  1038.  
  1039. The next counter we will look at is a 4-bit Synchronous counter.  It is
  1040. Synchronous because the change of each Flip-Flop occurs simultaneously.  The
  1041. sample circuit "SYNCOUNT.LG" illustrates this counter.  
  1042.  
  1043.   It also has a switch that clears the counter when set to FALSE and
  1044.   allows it to count when set to TRUE.  
  1045.  
  1046.   The AND gates synchronize all the Flip-Flops.  Both the J and K input
  1047.   connect to the output of an AND gate.  The input of the AND gate
  1048.   connects to all the previous Flip-Flop outputs.  The net effect is
  1049.   that the Flip-Flops will only toggle when all the previous Flip-Flops
  1050.   are TRUE. 
  1051.  
  1052. The next counter type is a 4-bit Synchronous counter with the ability to load
  1053. data.  The "LSCOUNT.LG" sample circuit illustrates this circuit.  This counter
  1054. is similar to the previous example, except logic has been added to allow the
  1055. counter to be preset to input data.  
  1056.  
  1057.   The AND gates on top synchronize the Flip-Flops.  
  1058.  
  1059.   The input data is represented by the fixed nodes (TRUE, FALSE, TRUE,
  1060.   FALSE) connected to the OR gates on the bottom.   
  1061.  
  1062.   All switches must be TRUE to count.  A FALSE value on a switch
  1063.   presets, clears, or loads data.  
  1064.  
  1065.   The switch just above the clock enables or disables the clock.  
  1066.  
  1067.   The switch just below the clock sets (loads) the counter the input
  1068.   data.  
  1069.  
  1070.   The switch at the bottom clears the counter. 
  1071.  
  1072.   The switch at the top presets the counter to all TRUE values.
  1073.  
  1074. The last counter type is an Up-Down Synchronous counter as illustrated in the
  1075. "UDCOUNT.LG" sample circuit.  
  1076.  
  1077.   The top switch decides if the counter will count forward (up) or
  1078.   reverse (down).  A TRUE value selects forward counting, and a FALSE
  1079.   value selects reverse counting.  
  1080.  
  1081.   The bottom switch decides if the counter will be cleared (all output
  1082.   set to FALSE) or count.  A TRUE value means count, and a FALSE value
  1083.   means clear.
  1084.  
  1085. BINARY ARITHMETIC
  1086.  
  1087. How does a digital computer perform arithmetic calculations?  
  1088.  
  1089. The Exclusive OR logical operator is the fundamental basis for a binary adder. 
  1090. Once you can add two numbers together, you can than subtract two numbers by
  1091. converting one number to its negative value and adding it to the other number. 
  1092.  
  1093.  
  1094. Let's start with the "Half-Adder."  This circuit adds two binary digits
  1095. together and has two outputs: Sum and Carry.  The Half-Adder is a variation on
  1096. the Exclusive OR circuit.  The "HALFADD.LG" sample circuit illustrates the
  1097. Half-Adder, as described by the following logical equations:
  1098.  
  1099.             Sum = A XOR B
  1100.           Carry = A AND B
  1101.  
  1102.   The two switches on the left represent the input.  
  1103.  
  1104.   The AND gate represents the Sum output.  
  1105.  
  1106.   The NOT gate represents the Carry output.
  1107.  
  1108. The truth table for a Half-Adder follows:
  1109.  
  1110.                               ╔═══════╦════════════╗
  1111.                               ║ Input ║   Output   ║
  1112.                               ╟───┬───╫─────┬──────╢
  1113.                               ║ A │ B ║ Sum │ Carry║
  1114.                               ╠═══╪═══╬═════╪══════╣
  1115.                               ║ 0 │ 0 ║  0  │   0  ║
  1116.                               ║ 0 │ 1 ║  1  │   0  ║
  1117.                               ║ 1 │ 0 ║  1  │   0  ║
  1118.                               ║ 1 │ 1 ║  0  │   1  ║
  1119.                               ╚═══╧═══╩═════╧══════╝
  1120.  
  1121. The "Full-Adder" is essentially two Half-Adders in series.  The Full-Adder has
  1122. three inputs: A, B, and Carry (C) from the previous least significant digit. 
  1123. It also has two outputs: Sum and Carry.  The "FULLADD.LG" sample circuit
  1124. illustrates a Full-Adder, as described by the following logical equations:
  1125.  
  1126.             Sum = (A XOR B) XOR C
  1127.           Carry = (A AND B) OR (A AND C) OR (B AND C)
  1128.  
  1129.   The two switches on the left represent the input to the adder.  
  1130.  
  1131.   The third switch in the middle represents the carry input from another
  1132.   Full-Adder.  (Mathematically it does not matter which switch
  1133.   represents the data input or the carry input.  However, by connecting
  1134.   the carry input to the middle switch, the number of gates the carry
  1135.   must pass through is kept to a minimum.)  
  1136.  
  1137.   The AND output represents the Sum output and the NAND output
  1138.   represents the Carry output.
  1139.  
  1140. The truth table for a Full-Adder follows:
  1141.  
  1142.                             ╔═══════════╦════════════╗
  1143.                             ║   Input   ║   Output   ║
  1144.                             ╟───┬───┬───╫─────┬──────╢
  1145.                             ║ A │ B │ C ║ Sum │ Carry║
  1146.                             ╠═══╪═══╪═══╬═════╪══════╣
  1147.                             ║ 0 │ 0 │ 0 ║  0  │   0  ║
  1148.                             ║ 0 │ 0 │ 1 ║  1  │   0  ║
  1149.                             ║ 0 │ 1 │ 0 ║  1  │   0  ║
  1150.                             ║ 0 │ 1 │ 1 ║  0  │   1  ║
  1151.                             ║ 1 │ 0 │ 0 ║  1  │   0  ║
  1152.                             ║ 1 │ 0 │ 1 ║  0  │   1  ║
  1153.                             ║ 1 │ 1 │ 0 ║  0  │   1  ║
  1154.                             ║ 1 │ 1 │ 1 ║  1  │   1  ║
  1155.                             ╚═══╧═══╧═══╩═════╧══════╝
  1156.  
  1157. Full-Adders can be connected in series to handle larger numbers.  A 4-bit
  1158. Adder uses four Full-Adders connected in series, where the Carry output of the
  1159. least significant Full-Adder becomes the Carry input of the next significant
  1160. Full-Adder.  The sample circuit "4BITADD.LG" illustrates this circuit.  
  1161.  
  1162.   The upper row of switches represents the first 4-bit number, and the
  1163.   lower set of switches represents the second 4-bit number.  Note that
  1164.   the least significant bit is on the left and the most significant bit
  1165.   is on the right, which is the reverse order that binary numbers are
  1166.   usually written.  
  1167.  
  1168.   The carry input of the least significant adder is preset to zero
  1169.   (FALSE).
  1170.  
  1171. Larger number can be added using more Full-Adders in series.  Today's
  1172. computers support 16-bit and 32-bit arithmetic.  The carry output must ripple
  1173. from left to right through the adder.  If you had a 16-bit or a 32-bit adder,
  1174. the time for the carry to ripple through all the Full-Adders is excessive. 
  1175. Production adders us a "Fast Carry" circuit to calculate all the carries
  1176. simultaneously.  Unfortunately, the number of additional logic gates makes the
  1177. screen too cluttered to follow what is happening.  The 4-bit Adder in the
  1178. library employees the "Fast Carry" logic.
  1179.  
  1180. Negative numbers are represented by using a method called "Two's-Compliment." 
  1181. This method has the property that when a positive number is added to its
  1182. negative counter part number, the answer is zero with the carry output set to
  1183. one.  As an example, a negative one is the largest possible number (all binary
  1184. ones).  The following table displays all sixteen possible binary numbers in a
  1185. 4-bit word and the corresponding decimal numbers when using Two's-Compliment:
  1186.                                ╔════════╤═════════╗
  1187.                                ║ Binary │ Decimal ║
  1188.                                ╟────────┼─────────╢
  1189.                                ║  0000  │    0    ║
  1190.                                ║  0001  │    1    ║
  1191.                                ║  0010  │    2    ║
  1192.                                ║  0011  │    3    ║
  1193.                                ║  0100  │    4    ║
  1194.                                ║  0101  │    5    ║
  1195.                                ║  0110  │    6    ║
  1196.                                ║  0111  │    7    ║
  1197.                                ║  1000  │   -8    ║
  1198.                                ║  1001  │   -7    ║
  1199.                                ║  1010  │   -6    ║
  1200.                                ║  1011  │   -5    ║
  1201.                                ║  1100  │   -4    ║
  1202.                                ║  1101  │   -3    ║
  1203.                                ║  1110  │   -2    ║
  1204.                                ║  1111  │   -1    ║
  1205.                                ╚════════╧═════════╝
  1206.  
  1207. To subtract two numbers, a computer uses the adder circuit and adds one number
  1208. to the negative of the other number.  To obtain the negative of the other
  1209. number, we invert each bit using the NOT gate and add one.  The negative of a
  1210. number is calculated using the "Two's-Compliment" method as follows:
  1211.  
  1212.                                  -A = (NOT A) + 1
  1213.  
  1214. The subtraction circuit uses the adder circuit, where the NOT gate is used to
  1215. invert the second number and the carry input is set to TRUE, to effectively
  1216. add one to the answer.  Finally, it inverts the carry out with a NOT gate so
  1217. the only time Carry out is TRUE, is when the answer is negative.
  1218.  
  1219. The "4BITSUB.LG" sample circuit illustrates the 4-bit subtraction circuit. 
  1220. This circuit solves the equation:
  1221.  
  1222.                                     C = A - B
  1223.  
  1224. The top row of switches is the A value, and the bottom row of switches is the
  1225. B value.  The answer is the sum output of each adder.  In all cases, the least
  1226. significant bit is on the left and the most significant bit is on the right.
  1227.  
  1228. This brings us to the next topic, multiplication.  To multiply two numbers
  1229. together, we will also use the adder circuit.  If we remember how long hand
  1230. multiplication is performed using decimal numbers, the same method applies to
  1231. binary numbers.  Let's look at the decimal multiplication of 12 times 14:
  1232.  
  1233.                     14
  1234.                    x12
  1235.                    ───
  1236.                     28
  1237.                   +14
  1238.                   ────
  1239.                    168
  1240.  
  1241. The same two numbers can be multiplied together using binary numbers as
  1242. follows:
  1243.  
  1244.              Binary               Decimal
  1245.  
  1246.               1110                  14
  1247.              x1100                 x12
  1248.              ─────                 ───
  1249.               0000                   0
  1250.              0000                    0
  1251.             1110                    56
  1252.           +1110                   +112
  1253.           ────────                ────
  1254.           10101000                 168
  1255.  
  1256. If we look at this method, we will observe that it is nothing but a series of
  1257. shifts and adds.  
  1258.  
  1259.   Start with zero as the answer.  
  1260.  
  1261.   Look at the least significant bit of the multiplier, if it is one, add
  1262.   the other number to the answer, otherwise skip this addition if it is
  1263.   zero.  
  1264.  
  1265.   Next shift the other number one place to the left and look at the next
  1266.   significant bit in the multiplier.  
  1267.  
  1268. Repeat this process for each bit in the multiplier.  Notice that 4-bit
  1269. multiplication can result in an 8-bit answer.
  1270.  
  1271. The "MULTIPLY.LG" sample circuit illustrates a 4-bit multiply circuit.  This
  1272. circuit contains four adder circuits.  
  1273.  
  1274.   The bottom left adder adds the first two results, and the bottom right
  1275.   adder adds the last two results.  
  1276.  
  1277.   The top adders add the results of the adders on the bottom.  In this
  1278.   method there are no clock cycles or shift steps required.  
  1279.  
  1280.   The four switches on the left represent one value, and the four
  1281.   switches on the bottom represent the other value.  Note that all
  1282.   numbers are represented with least significant bit on the left,
  1283.   instead of most significant bit as depicted when written on paper.  
  1284.  
  1285.    The 10-bit answer is displayed across the top of the screen.
  1286.  
  1287. This circuit only handles positive numbers.  To multiply a mix of positive and
  1288. negative numbers, requires additional circuits to convert negative numbers to
  1289. positive before performing the multiplication, and when necessary converting
  1290. the answer to a negative number after performing the multiplication.
  1291.  
  1292. A computer can perform division, by using a series of shifts and subtractions. 
  1293.  
  1294.  
  1295.   To start, the divisor is shifted all the way to the left.  
  1296.  
  1297.   Next subtract the divisor from the numerator.
  1298.  
  1299.   If the resulting subtraction is positive, the next bit of the answer
  1300.   is set to one and the numerator is replaced with the results of the
  1301.   subtraction.  
  1302.  
  1303.   If the resulting subtraction is negative, (the divisor is larger then
  1304.   the numerator), the numerator does not change and the next bit in the
  1305.   answer is zero.  
  1306.  
  1307.   Finally, the divisor and the answer are shifted right one place and
  1308.   the process continues.  
  1309.  
  1310. When dividing two 4-bit numbers, the answer consists of a 4-bit quotient and a
  1311. 4-bit remainder.  As an example, if we divide 11 by 2, the quotient is 5 and
  1312. the remainder is 1.  Let's look at this same example using binary numbers:
  1313.             Binary        Answer         Decimal
  1314.               1011                         11
  1315.           -0010000                        -16 (2*8)
  1316.           ────────                        ───
  1317.           (negative)        0             (negative)
  1318.  
  1319.               1011                         11
  1320.           -0001000                        - 8 (2*4)
  1321.           ────────                        ───
  1322.               0011          1               3
  1323.  
  1324.               0011                          3
  1325.           -0000100                        - 4 (2*2)
  1326.           ────────                        ───
  1327.           (negative)        0             (negative)
  1328.  
  1329.               0011                          3
  1330.           -0000010                        - 2 (2*1)
  1331.           ────────                        ───
  1332.               0001          1               1
  1333.  
  1334. The answer is 0101 (5) with a remainder 0001 (1).  When the subtraction
  1335. results in a positive number, the answer is one, otherwise zero.  The
  1336. remaining value after all four subtractions is the remainder.
  1337.  
  1338. The 4-bit divide circuit is too complicated to be shown on the screen, but can
  1339. be found in the Library of Components.
  1340.  
  1341. Today's computers typically use 16 or 32 bits to represent integers. 
  1342. Therefore, they can represent larger numbers.  16-bit integers can be as large
  1343. as 32,767 and 32-bit integers can be as large as 2,147,483,647.
  1344.  
  1345. FLOATING POINT ARITHMETIC
  1346.  
  1347. So far we have explored arithmetic of whole numbers called integers.  Integers
  1348. can be positive or negative, but only whole numbers (e.g., 0, 1, 2).  This
  1349. brings us to the next topic called floating point numbers.  Floating point
  1350. numbers contains a decimal point (e.g., 3.1416).  Floating point numbers get
  1351. their name from fact that the decimal point can be moved within a number
  1352. maintaining the same number of digits (precision) but take on different
  1353. values.  As an example, numbers with six decimal places of precision include:
  1354. 12345.6 and 1.23456.  
  1355.  
  1356. Floating point numbers are usually represented in scientific notation. 
  1357. Scientific notation for base 10 numbers is a number times ten raised to a
  1358. power.  As an example 12345.6 can be represented as:
  1359.  
  1360.           1.23456 x 10**4
  1361.  
  1362. where "**" means raised to the power, so 10**4 is 10x10x10x10 or 10,000
  1363.  
  1364. The number is usually shown with one digit to the left of the decimal point.
  1365.  
  1366. In general, floating point numbers are less accurate than integers, since
  1367. fractional numbers are represented by a finite precision, and some numbers
  1368. require infinite precision to be properly represented.  As an example the
  1369. fraction 1/3 corresponds to 0.33333333 ..., where an infinite number of threes
  1370. are required to accurately represent this fraction.
  1371.  
  1372. Scientific notation supports positive and negative numbers.  It also supports
  1373. positive and negative exponents.  The following are several examples:
  1374.  
  1375.           +1.23456 x 10**4
  1376.           -1.23456 x 10**4
  1377.           +1.23456 x 10**(-4)
  1378.           -1.23456 x 10**(-4)
  1379.  
  1380. The computer uses base 2 to represent floating point numbers.  A floating
  1381. point number consists of three components: sign, exponent, and mantissa.  The
  1382. sign determines if the number is positive or negative.  The exponent
  1383. determines the power that two is raised to, and the mantissa represents the
  1384. normalized number.  As an example: the decimal number 5 can be represented as
  1385. the following binary number in scientific notation.
  1386.  
  1387.           +1.01 x 2**10
  1388.  
  1389. Where the "+" sign at the front of the number specifies the sign, showing the
  1390. number is positive.  1.01 is the mantissa and the binary value 10 (decimal 2)
  1391. is the exponent.  The exponent shows that the decimal point should be moved
  1392. two places to the right.  Therefore +1.01 x 2**10 becomes:
  1393.  
  1394.           101.0, which corresponds to a decimal 5.
  1395.  
  1396. The fraction 3/8 can be represented by the following floating point number:
  1397.  
  1398.           +1.1 x 2**(-10)
  1399.  
  1400. Since the exponent is negative, the decimal point must be moved to the left
  1401. two binary place resulting in the value 0.011 that corresponds to 3/8. 
  1402.  
  1403. There are many possible ways to represent a floating point number in a
  1404. computer.  Let's look at a hypothetical 8-bit format that I designed for use
  1405. with this program.  This format consists of a 1-bit sign, 3-bit exponent, and
  1406. 4-bit mantissa as follows:
  1407.  
  1408.                                     s eee mmmm
  1409.  
  1410.   where:     s is the sign bit, 0 = positive, 1 = negative
  1411.            eee is the exponent, where 011 corresponds to 2**0
  1412.           mmmm is the mantissa, which is left justified
  1413.  
  1414.  
  1415. By convention when the sign bit is zero, the number is positive.  Conversely,
  1416. when the sign bit is one, the number is negative.  Now comes the tricky part. 
  1417. How do we represent negative exponents?  We could use two's-compliment.  I
  1418. instead choose a format that is more consistent with how computers actually
  1419. store this value.  By convention an exponent value of 011 corresponds to an
  1420. exponent of zero.  Values greater than 011 are positive exponents and values
  1421. less then 011 are negative exponents.  The mantissa is very straight forward. 
  1422. It is always left justified such that the left most bit is always a one.  As
  1423. an example the previously discussed numbers are transformed into the following
  1424. 8-bit floating point format:
  1425.  
  1426.                        Floating-Point Binary             Binary
  1427.                        Notation       Scientific         Decimal
  1428.                        s eee mmmm     Notation           Notation
  1429.                        - --- ----     ---------------    --------
  1430.                    5 = 0 101 1010 or  1.01 x 2**10    or  101.0
  1431.                   -5 = 1 101 1010 or -1.01 x 2**10    or -101.0
  1432.                  3/8 = 0 001 1100 or  1.10 x 2**(-10) or  0.011
  1433.                 -3/8 = 1 001 1100 or -1.10 x 2**(-10) or -0.011
  1434.  
  1435. Obviously, no computer would attempt to use an 8-bit floating point format. 
  1436. But this format will be useful in showing how floating point numbers are
  1437. manipulated.
  1438.  
  1439. The Institute of Electrical and Electronic Engineers (IEEE) 754 specification
  1440. defines the most widely used floating point formats in today's computers. 
  1441. They are the IEEE 32-bit and IEEE 64-bit floating point formats.  The Intel
  1442. math coprocessor uses these two formats and an additional 80-bit floating
  1443. point format.  The following table summarizes these floating point formats:
  1444.  
  1445.                      ╔════════╤═══════╤══════════╤══════════╗
  1446.                      ║ Format │ Sign  │ Exponent │ Mantissa ║
  1447.                      ╟────────┼───────┼──────────┼──────────╢
  1448.                      ║ 32-bit │ 1-bit │   8-bit  │  23-bit  ║
  1449.                      ║ 64-bit │ 1-bit │  11-bit  │  52-bit  ║
  1450.                      ║ 80-bit │ 1-bit │  15-bit  │  64-bit  ║
  1451.                      ╚════════╧═══════╧══════════╧══════════╝
  1452.  
  1453. The sign bit is always first, followed by the exponent, and finally the
  1454. mantissa.  
  1455.  
  1456. The sign bit is zero for positive numbers and one for negative numbers.
  1457.  
  1458. The exponents are stored as a positive number.  To represent negative
  1459. exponents values, the exponent is biased by half it possible value.  For 8-bit
  1460. exponents the bias is 127, for 11-bit exponents the bias is 1,023, and for
  1461. 15-bit exponents the bias is 16,383.  You compute the actual exponent value by
  1462. subtracting the bias value from the exponent value.  As an example, an
  1463. exponent of -5 in an 8-bit exponent would be represented by 127 - 5 = 122
  1464. (base ten) or 0111111 - 00000101 = 01111010 (base 2).
  1465.  
  1466.  
  1467. The IEEE formats have one twist concerning the handling of the mantissa.  The
  1468. mantissa is stored as a binary fraction greater than or equal to one and less
  1469. than two.  The mantissa is always left justified and the first bit is always a
  1470. one (well almost always).  The first bit is not actually stored in the format,
  1471. instead it is assumed to be one and the next 23 or 52 bits are the remainder
  1472. of the number.  In this manner an additional bit of precision is obtained for
  1473. the 32-bit and 64-bit formats.  In other words, the 32-bit format has 24 bits
  1474. of precision and the 64-bit format has 53-bits of precision.  The only
  1475. exception is the number zero, which is always represented by all zeros (sign,
  1476. exponent, and mantissa).  This is a special case, since the exponent is never
  1477. allowed to be all zeros for a non-zero number.
  1478.  
  1479. How big of a number can these floating point formats represent?  
  1480.  
  1481. This is not a simple question.  Let's analyze the IEEE 32-bit format.  The
  1482. 23-bit mantissa can represent numbers as large as 2**24 (since the first bit
  1483. is always assumed to be one).  2**24 is approximately 1.7 x 10**7.  In other
  1484. words the mantissa is equivalent to a seven decimal place number.  The 8-bit
  1485. exponent is in effect ±2**7 or ±128.  Remember this is the value of the
  1486. exponent, we must still raise two to this power.  Hence the largest number is
  1487. 2**128 or approximately 3.4 x 10**38.  
  1488.  
  1489. So the proper answer to the question "How big of a number can the IEEE 32-bit
  1490. format handle?", is a seven decimal place number within the range ±3.4 x
  1491. 10**38.  There is actually another limit we have not discussed, and that is
  1492. how small of a number can be represented as the number approaches zero?  The
  1493. answer is 2**(-126) or approximately 1.2 x 10**(-38).
  1494.  
  1495. With the limitation on how large and how small a number can handle, there are
  1496. some error conditions that must be addressed.  The first is called an
  1497. "Over-Flow" condition.  Which means the resulting number is too large to be
  1498. represented by the floating point format.  Think of multiplying two very large
  1499. 32-bit floating point numbers together and the result being larger than 3.4 x
  1500. 10**38.  This error shows that the exponent could not represent the resulting
  1501. number and therefore the exponent over flowed.  
  1502.  
  1503. The next error condition is called an "Under-Flow" condition.  This occurs
  1504. when a number becomes two small as it approaches zero.  As an example if we
  1505. divide a very small number by a very large number, the result can be smaller
  1506. than 1.2 x 10**(-38).  In this case the exponent becomes two small to
  1507. represent the number and therefore it under flowed.
  1508.  
  1509. The last error condition I will mention is the division by zero.  Other error
  1510. conditions also exist and are defined by the IEEE 754 specification.
  1511.  
  1512. The following table summarizes the three floating point formats in terms of
  1513. their decimal limits:
  1514.  
  1515.             ╔════════╤═══════════╤═══════════════╤══════════════════╗
  1516.             ║ Format │ Precision │ Largest Value │ Smallest Value   ║
  1517.             ╟────────┼───────────┼───────────────┼──────────────────╢
  1518.             ║ 32-bit │  7 places │ ±3.4x10**38   │ ±1.2x10**(-38)   ║
  1519.             ║ 64-bit │ 15 places │ ±1.8x10**308  │ ±2.2x10**(-308)  ║
  1520.             ║ 80-bit │ 19 places │ ±1.2x10**4932 │ ±3.4x10**(-4932) ║
  1521.             ╚════════╧═══════════╧═══════════════╧══════════════════╝
  1522.  
  1523. Let's discuss 32-bit floating point arithmetic, starting with addition.  We
  1524. cannot simply add the two mantissas together using an integer addition
  1525. circuit.  We must first decide which number is larger, i.e., which exponent is
  1526. larger.  The smaller exponent is subtracted from the larger exponent.  The
  1527. resulting number is the number of binary places the smaller number's mantissa
  1528. must be shifted to the right before being added to the larger number.  Since
  1529. the mantissa is always positive, the sign bit determines if we add or subtract
  1530. these numbers.  
  1531.  
  1532. The following example looks at adding 5 and -3/8:
  1533.  
  1534.             5     0 10000001 01000000000000000000000
  1535.           -3/8    1 01111101 10000000000000000000000
  1536.  
  1537. Step 1:   Determine the Larger Exponent.  The exponent for 5 is larger than the
  1538.           exponent for -3/8
  1539.  
  1540. Step 2:   Subtract the smaller exponent from the larger exponent:
  1541.  
  1542.            10000001       (+2)
  1543.           -01111101       (-2)
  1544.           ─────────
  1545.            00000100       (+4)
  1546.  
  1547. Step 3:   Restore the leading 1 to each mantissa 
  1548.  
  1549.           101000000000000000000000
  1550.           110000000000000000000000
  1551.  
  1552. Step 4:   Shift the smaller number to the right the calculated number of places
  1553.           (4 places)
  1554.  
  1555.           101000000000000000000000
  1556.           0000110000000000000000000000
  1557.  
  1558. Step 5:   Check sign bit and decide if we add or subtract these numbers. There
  1559.           are four possibilities that have to be addressed.  
  1560.  
  1561.                            ╔═══════╦═════════╤════════╗
  1562.                            ║ Input ║         │        ║
  1563.                            ╟───┬───║  Action │ Result ║
  1564.                            ║ A │ B ║         │        ║
  1565.                            ╠═══╪═══╬═════════╪════════╣
  1566.                            ║ + │ + ║   A + B │   +    ║
  1567.                            ║ + │ - ║   A - B │   ?    ║
  1568.                            ║ - │ + ║   B - A │   ?    ║
  1569.                            ║ - │ - ║   A + B │   -    ║
  1570.                            ╚═══╧═══╩═════════╧════════╝
  1571.  
  1572.   In this case we subtract the smaller number from the larger number
  1573.   using a 24-bit addition (or subtraction) circuit.
  1574.  
  1575.            101000000000000000000000
  1576.           -000011000000000000000000
  1577.           ─────────────────────────
  1578.            100101000000000000000000 Step 6:   If necessary, shift the mantissa such that a one is always in the
  1579.           first column.  If we added two numbers together, it is possible that a
  1580.           carry condition would occur and the number would have to be shifted to
  1581.           the right one place.  If we subtracted two numbers of comparable size,
  1582.           it is possible the answer may have to be shifted as much as 23 places
  1583.           to the left.  Note that floating point subtraction can result in
  1584.           significant loss in precision.  For each place to the right we shift
  1585.           the number we must increment the exponent of the larger number.  For
  1586.           each place to the left we shift the number we must decrement the
  1587.           exponent by that many places.  In this example it was not necessary to
  1588.           shift the answer or adjust the exponent.
  1589.  
  1590. Step 7:   The next step is to determine the sign of the answer.  Again refer to
  1591.           the four possibilities identified in step 5.  In this example, the
  1592.           sign bit should be positive, since the result is a positive number.
  1593.  
  1594. Step 8:   Store the answer in a floating point format.
  1595.  
  1596.           0 10000001 001010000000000000000000     (4 5/8)
  1597.  
  1598. If the smaller number's exponent is less than the larger number's exponent by
  1599. more than the number of precision bits in the mantissa, it will not contribute
  1600. at all to the answer.  As an example if the exponent of a 32-bit floating
  1601. point number is 56 for the larger number and 26 for the smaller number, the
  1602. difference is 30.  Since there are only 24 bits in the mantissa, we would have
  1603. to shift the smaller number 30 places to the right before adding it to the
  1604. larger number.   It would not contribute to the answer.
  1605.  
  1606. For floating point subtraction, we simply use the floating point addition, as
  1607. described above, except we invert the sign of the second number using a NOT
  1608. gate.  In other words, if the second number is positive we make it negative,
  1609. or vice versa.
  1610.  
  1611. Fortunately, the floating point multiply is much simpler.  Let's first look at
  1612. a simple decimal example.  If we multiply 1 x 10**4 times 2 x 10**5, the
  1613. answer is 2 x 10**9.  This multiply can be viewed as 1 times 2 and 10**4 times
  1614. 10**5.  1 times 2 is obviously 2.  To multiply 10**4 by 10**5 we can simply
  1615. add the exponents (4+5) and get 10**9.  Similarly, in a floating point format
  1616. all we do is add the exponents and multiply the mantissas.
  1617.  
  1618. In the following example we will multiply 5 by -3/8:
  1619.  
  1620. Step 1:   Restore the leading 1 to each mantissa 
  1621.  
  1622.           101000000000000000000000
  1623.           110000000000000000000000
  1624.  
  1625. Step 2:   Multiply the two mantissas together.  Note the answer requires twice
  1626.           as many bits as the numbers being multiplied.  In this example, two
  1627.           24-bit numbers result in a 48-bit answer.  However, since we will only
  1628.           store 24-bits of the answer, we only need to multiply the first
  1629.           13-bits of each mantissa using a 13-bit integer multiply circuit.
  1630.  
  1631.                         1010000000000
  1632.                        x1100000000000
  1633.           ───────────────────────────
  1634.             101000000000
  1635.           +101000000000
  1636.           ───────────────────────────
  1637.           011110000000000000000000000
  1638.  
  1639. In this example the resulting left most bit is a zero and should be discarded. 
  1640. Sometimes the resulting left most bit will be a one.  In those cases, you do
  1641. not discard the first digit, and must increment the results of the exponent
  1642. calculation.
  1643.  
  1644. Step 3:   Next we add the two exponents using an 8-bit adder.  To correct for
  1645.           the bias of 01111111, which could be subtracted from each exponent be
  1646.           fore added, and added back afterward, or we could add the two
  1647.           exponents unchanged and then subtract the bias once.
  1648.  
  1649.            10000001
  1650.           +01111101
  1651.           ─────────
  1652.            11111110
  1653.           -01111111
  1654.           ─────────
  1655.            01111111
  1656.  
  1657.   The new exponent becomes 01111111.
  1658.  
  1659. Step 4:   Calculate the sign bit.  Since we are multiplying two number together,
  1660.           the resulting sign bit is the Exclusive OR of the two bits.
  1661.  
  1662.           Sign bit = A XOR B
  1663.  
  1664.           1 = 1 XOR 0
  1665.  
  1666.   Therefore, if one and only one of the numbers is negative, the answer
  1667.   is also negative.
  1668.  
  1669. Step 5:   Store the answer in a floating point format.
  1670.  
  1671.           1 01111111 111000000000000000000000     (-1 7/8)
  1672.  
  1673. Let's look at the "FPMULTP.LG" sample circuit.  In this circuit we are using
  1674. my hypothetical 8-bit floating point format described earlier.  It consisted
  1675. of a 1-bit sign, followed by a 3-bit exponent, and a 4-bit mantissa.  Unlike
  1676. the IEEE format, we will preserve the leading 1 in the mantissa.  The top row
  1677. of switches represents the first number and the bottom row of switches
  1678. represents the second number.  The switches are organized into three groups: 
  1679. The left group of switches represents the sign bit, the middle group of
  1680. switches represents the exponent, and the right group of switches represents
  1681. the mantissa.  The exponent and mantissa are organized in the order you would
  1682. write the number on paper with the most significant bit on the left and the
  1683. least significant bit on the right.  The answer is the output nodes along the
  1684. top of the screen.  Since the Add and Multiply library circuits are organized
  1685. in reverse order (least significant bit on left and most significant bit on
  1686. right) the connections cross over on both input and output.  Finally, the
  1687. "A or B" library item in the upper right-hand portion of the screen is a 4-bit
  1688. wide 1 of 2 selector used to correct the condition when the resulting most
  1689. significant bit is zero by shifting the answer one bit to the left or
  1690. subtracting one from the exponent.
  1691.  
  1692. (The sample circuit "AORB.LG" illustrates the 4-bit wide 1 of 2 selector).
  1693.  
  1694. Let's plug in some real values to see how it works.  In this example we will
  1695. multiply 5 times -3/8.  You should set the switches as follows where 0
  1696. corresponds to FALSE and 1 corresponds to TRUE:
  1697.  
  1698.                                        s eee mmmm
  1699.                                        - --- ----
  1700.                                     5: 0 101 1010
  1701.                                  -3/8: 1 001 1100
  1702.  
  1703. The answer should be -1.875 (-1 7/8) or 1 011 1111 in binary.  You are welcome
  1704. to try other combinations of numbers.
  1705.  
  1706. Floating point division is very similar to floating point multiplication. 
  1707. Except the exponents are subtracted and the bias is added back in.  The
  1708. mantissas are divided instead of multiplied.  Unlike, integer division where
  1709. we have a quotient and a remainder, there is no concept of a remainder in
  1710. floating point division.  The circuit must continue to shift and subtract
  1711. until the answer has the required significant bits.  If the two mantissas are
  1712. nearly the same value, the division circuit may have to shift as much as twice
  1713. the number of bits in the mantissa before obtaining the answer.
  1714.  
  1715. ARITHMETIC LOGIC UNIT (ALU)
  1716.  
  1717. Now that we looked at logic circuits and arithmetic circuits, it is time to
  1718. look at how a computer would use these circuits.  A computer only understands
  1719. "machine language" which consists of binary numbers.  To program a computer in
  1720. machine language you normally use a language called "Assembly Language" where
  1721. each line corresponds to a single machine language instruction.  We will only
  1722. discuss the following hypothetical 8 assembly language instructions:
  1723.  
  1724.         Assembly       Logical
  1725.         Language       Equations      Description
  1726.         --------       -----------    -------------
  1727.         NOT A          A = NOT A      (Inverter)
  1728.         AND A, B       A = A AND B    (Logical And)
  1729.         OR  A, B       A = A OR B     (Logical Or)
  1730.         XOR A, B       A = A XOR B    (Exclusive Or)
  1731.         INC A          A = A + 1      (Increment)
  1732.         DEC A          A = A - 1      (Decrement)
  1733.         ADD A, B       A = A + B      (Addition)
  1734.         SUB A, B       A = A - B      (Subtraction)
  1735.  
  1736. Notice the answer is always stored in A.  For this reason A is usually called
  1737. the accumulator.  We will only discuss integer arithmetic.
  1738.  
  1739. Let's start by looking at how a computer implements logic circuits.  The
  1740. computer applies the logical operators (NOT, AND, OR, or XOR) to each bit
  1741. separately.  The number of logic gates required to implement these
  1742. instructions depends on the number of bits in a particular computer's word. 
  1743. In our example, we will be using 4-bits per word.  A typical computer would
  1744. use 16-bits or 32-bits per word.  (Some computers may use less, like 8-bits
  1745. per word, and some computers may use more, like 64-bits per word).  In other
  1746. words, a 4-bits per word requires four logic gates, one for each bit.  The
  1747. least significant bit of word A will be paired with the least significant bit
  1748. of word B.  The remaining three bits in word A would be paired with their
  1749. corresponding bits in word B.
  1750.  
  1751. The "LU.LG" sample circuit illustrates the computer "Logic Unit."  This
  1752. circuit implements the 4-bit NOT, AND, OR, and XOR instructions.  
  1753.  
  1754.   Word A is represented by the fixed values TRUE, FALSE, TRUE, FALSE. 
  1755.   Word B is represented by the fixed values TRUE, TRUE, FALSE, FALSE.  
  1756.  
  1757. There are three inputs to this circuit, all of which enter the "2 to 4"
  1758. circuit.  The right most switch, connected to the left input of the "2 to 4"
  1759. circuit, enables this circuit when it is set to FALSE.  When it is set to
  1760. TRUE, this circuit disables all the 3-state units.  When this switch is set to
  1761. FALSE, the circuit is enabled, and the remaining two switches are used to
  1762. select the appropriate logical operator (NOT, AND, OR, or XOR).  Notice that
  1763. the NOT logical operator does not use word B.  It only operates on word A.
  1764.  
  1765. Now let's look at the computer's "Arithmetic Unit" as illustrated in the
  1766. "AU.LG" sample circuit.  Word A is on the right directly connected to the Add
  1767. unit and is represented by the fixed values FALSE, TRUE, FALSE, TRUE or 0101
  1768. binary.  Word B is on the left and is represented by the fixed values FALSE,
  1769. FALSE, TRUE, TRUE or 0011 binary.  The "Carry-In" input is represented by the
  1770. FALSE value or zero binary in the upper left portion of the circuit.
  1771.  
  1772. This circuit also has three input switches: enable and two selector switches. 
  1773. The enable switch is on the far right.  The switch in the middle selects
  1774. between addition and subtraction.  When this switch is FALSE, it is selecting
  1775. addition, and when it is TRUE it is selecting subtraction.  When the switch on
  1776. the bottom left is set to TRUE word B is set to 0001 (one) and the carry-in
  1777. bit is set to zero.  Under this configuration the circuit implements the
  1778. increment or decrement instruction as determined by the value of the middle
  1779. switch.  
  1780.  
  1781. Next we will look at the "ALU.LG" sample circuit.  This circuit illustrates
  1782. the combined Arithmetic and Logic circuits described above and is referred to
  1783. as the "Arithmetic Logic Unit" or ALU.  This circuit has four input switches:
  1784. three are used to select one of the eight operations to be performed (ADD,
  1785. SUB, INC, DEC, NOT, AND, OR, and XOR) and the last switch is used to enable or
  1786. disable the output.  The enable switch is located closest to the top of the
  1787. screen.  The switch located on the left selects between the Arithmetic Unit
  1788. (when FALSE) and the Logic Unit (when TRUE).  The remaining two switches
  1789. select the individual operations of these units.
  1790.  
  1791. The FALSE fixed node toward the top of the screen represents the value zero
  1792. for the carry-in data.  The next four fixed values (TRUE, FALSE, TRUE, FALSE)
  1793. represent word A, but because these values are ordered least significant bit
  1794. to most significant bit, they represent the binary value 0101.  Word B is
  1795. represented by the bottom four fixed values (TRUE, TRUE, FALSE, FALSE) or 0011
  1796. binary.  
  1797.  
  1798. The following table identifies the results of the eight possible operations: 
  1799. Notice the circuit organizes the input and output data least significant bit
  1800. to most significant bit which is in reverse order as written in the table.
  1801.  
  1802.                       ╔═════════╦═════╤══════════╤════════╗
  1803.                       ║S2 S1 S0 ║ Opr.│ Equation │ Output ║
  1804.                       ╠═════════╬═════╪══════════╪════════╣
  1805.                       ║ 0  0  0 ║ ADD │  A + B   │  1000  ║
  1806.                       ║ 0  0  1 ║ INC │  A + 1   │  0110  ║
  1807.                       ║ 0  1  0 ║ SUB │  A - B   │  0010  ║
  1808.                       ║ 0  1  1 ║ DEC │  A - 1   │  0100  ║
  1809.                       ║ 1  0  0 ║ NOT │  NOT A   │  1010  ║
  1810.                       ║ 1  0  1 ║  OR │ A OR B   │  0111  ║
  1811.                       ║ 1  1  0 ║ AND │ A AND B  │  0001  ║
  1812.                       ║ 1  1  1 ║ XOR │ A XOR B  │  0110  ║
  1813.                       ╚═════════╩═════╧══════════╧════════╝
  1814.  
  1815. where: S2, S1, and S0 are the selector switches from left to right.
  1816.  
  1817. The ALU is the brain of the computer.  It performs all the integer
  1818. calculations.  Most computers have additional instructions in their ALU, such
  1819. as multiply and divide.  The floating point instructions are normally
  1820. performed by a separate unit called the "Floating Point Unit" or FPU.  If we
  1821. look at the Intel family of microprocessors we find the original 8088, 286,
  1822. and 386 contained the ALU and the 8087, 287, and 387 contained the
  1823. corresponding FPU.  The 486 (DX, DX2, and DX4 models) was the first Intel
  1824. microprocessor to contain an ALU and an FPU.  The Pentium microprocessor
  1825. actually contains two ALUs and one FPU.
  1826.  
  1827. The next logical step is to build the "Central Processing Unit" or CPU. 
  1828. However, this requires additional circuits to access memory, decode
  1829. instructions, and provide registers for results stored within the CPU.  Due to
  1830. the limitation of the screen being too small, we are not able to generate a
  1831. sample CPU circuit.
  1832.  
  1833. Instead I will only discuss some common functions of a CPU.  Let's start by
  1834. looking at the different types of instructions the CPU processes.
  1835.  
  1836. The first family of instructions I will discuss is the Move instruction, which
  1837. is normally abbreviated "MOV."  The move instruction moves data between the
  1838. Random Access Memory (RAM) and the CPU registers.  Also, if the CPU has
  1839. multiple registers, it can move data between the registers within the CPU. 
  1840. There are other variations on the move instruction including the Move-
  1841. Immediate which loads the next piece of data in the instruction stream as data
  1842. instead of an address pointing to the data.
  1843.  
  1844. Besides storing data in registers, the CPU keeps track of the state of each
  1845. calculations in a special register called the "Flag-Register."  Each bit in
  1846. the flag-register represents a different state and is called a "flag."  As an
  1847. example, if you look closely at the ALU sample circuit, you will see both the
  1848. LU and AU unit have two additional outputs labeled "c" and "z."  These are the
  1849. carry-out flag and zero flag bits that are set as a result of the calculation
  1850. performed.  The AU sets the carry-out flag any time the carry-out bit is set. 
  1851. Both the AU and the LU set the zero flag any time all four bits of the output
  1852. are set to zero.  The carry-out flag can be used as an input to the next
  1853. calculation for calculating values larger than the normal width of the word,
  1854. in our case 4-bits.  The zero flag can be used by other instructions for
  1855. performing conditional operations depending on the results of the calculation.
  1856.  
  1857. Most computers have a "Jump," abbreviated "JMP," and conditional jump
  1858. instruction.  These instructions are used to implement the IF-THEN-ELSE
  1859. instructions normally found in most high level languages.  Another example of
  1860. using a conditional jump instruction would be a loop that decrements a
  1861. counter.  The last instruction in the loop might be "Jump to top of the loop
  1862. if counter is not zero."  As long as the counter is not zero, the loop will
  1863. continue to be processed.  Of course, you must decrement the counter somewhere
  1864. in the loop, otherwise the program would never leave this loop.
  1865.  
  1866. Another very important family of instructions is the "Call" and "Return"
  1867. instructions.  These instructions are used to support subroutines and
  1868. functions.  When a computer calls a subroutine, it places the address of the
  1869. instruction following the call instruction in a piece of memory called the
  1870. stack.  When the subroutine completes, it executes the return instruction that
  1871. jumps back to the address stored in the stack.  A stack is a portion of normal
  1872. RAM set aside just for calling subroutines.  The CPU keeps two pointer
  1873. registers.  The first one is used to point to the instructions and the other
  1874. points to the stack.  Normally, a high level language will use a series of
  1875. PUSH instructions to save the registers on the stack and use the POP
  1876. instruction to restore these registers to their original value when returning
  1877. from the subroutine.  Also, the PUSH and POP instructions can be used to pass
  1878. parameters to the subroutine.
  1879.  
  1880. MEMORY
  1881.  
  1882. A computer can have several types of memory.  Memory can be separated into two
  1883. categories: "Read Only Memory" or ROM, and "Random Access Memory" or RAM. 
  1884. These categories can be further subdivided either by type or by function.
  1885.  
  1886. ROM is permanent memory that cannot be changed and retains its value when the
  1887. computer is powered off.  Functionally, ROMs contain instructions used to
  1888. start the computer and interface with the hardware of the computer.  There are
  1889. system ROMs, video ROMs, Disk controller ROMs, etc.  These types of ROMs
  1890. function as Basic Input and Output System (BIOS) allowing the software
  1891. programs to access the hardware without knowing the details of the hardware
  1892. installed.  Originally an ROM implied a circuit that had its software programs
  1893. (instructions) etched in.  
  1894.  
  1895. Today, there are Programmable ROMs (PROM) that start with a generic circuit
  1896. with little fuses that can be one time blown in a pattern representing the
  1897. software program.  
  1898.  
  1899. Also, there is an Erasable PROM (EPROM) that can be programmed using special
  1900. equipment and erased by shining ultraviolet light on the chip.  
  1901.  
  1902. The latest technology, called Flash PROM, can be programmed by the computer
  1903. without using special equipment.
  1904.  
  1905. Just like there are several types and functions of ROMs, there are several
  1906. types and functions of RAM.  In general, RAM is used to store instructions and
  1907. data that the CPU processes.  Software programs can be read from disk and
  1908. loaded into RAM.  Once in RAM, the CPU can process the instructions contained
  1909. in the software program.  When it needs to load another software program, it
  1910. can overwrite the first software program since it is no longer needed and can
  1911. be loaded from disk the next time it is executed.  Some hardware, like the
  1912. video adapter, also contains RAM.  This RAM is used to contain the images that
  1913. are being displayed on the monitor.
  1914.  
  1915. RAM can be categorized into two types: Static RAM and Dynamic RAM.  Static RAM
  1916. is faster, larger, cost more, and uses more power than Dynamic RAM.  
  1917.  
  1918. Static RAM can be constructed from logic gates.  The CPU register described
  1919. above is a type of static RAM.  
  1920.  
  1921. Dynamic RAM uses a 2-dimensional matrix of small capacitors etched into the
  1922. silicon chip to store information.  Like most capacitors, they will gradually
  1923. lose their charge and eventually forget the information stored in them. 
  1924. Consequently, dynamic RAM must be refreshed several thousand times per second. 
  1925. There is special circuitry external to the CPU that periodically instructs the
  1926. dynamic RAM to read and write back one row of memory to refresh the values
  1927. stored in the capacitors.  By working on one row at a time, a Megabyte (a
  1928. million bytes) of RAM can be fully refreshed with only one thousand accesses
  1929. instead of a million accesses.  The number of accesses required to fully
  1930. refresh dynamic RAM is the square root of the chip size.  As an example, a 4-
  1931. Mbit chip requires 2,048 accesses, a 16-Mbit chip requires 4,096 accesses to
  1932. fully refresh the chip.
  1933.  
  1934. The last type of RAM I will discuss is called "Cache."  In computer terms, a
  1935. cache is a small but fast static memory located between the CPU and the slower
  1936. dynamic RAM.  The cache stores the most recently accessed memory in
  1937. anticipation that the computer will need it again.  As an example, if the CPU
  1938. is processing a loop in a software program, the instructions in the loop will
  1939. be accessed over and over again until it exits the loop.  Since the dynamic
  1940. RAM is several times slower than the CPU, a cache can be used to speed up the
  1941. performance.
  1942.  
  1943. Now, let's look at the "DATA.LG" sample circuit.  This circuit is a static RAM
  1944. example of a single 4-bit word.  Each bit is a data latch as described
  1945. earlier.  The switch on the lower right clears (zero) memory when it is FALSE. 
  1946. The switch in the upper left is the enable switch.  It sets memory to the
  1947. values on the input when it is FALSE.  Both switches should not be set to
  1948. FALSE simultaneously.  When both switches are TRUE, the RAM remembers the last
  1949. setting and ignores the input.  For illustrative purposes, the input is preset
  1950. to TRUE, FALSE, TRUE, and FALSE.
  1951.  
  1952. Let's look at the "RAM.LG" sample circuit.  This circuit combines four 4-bit
  1953. static RAM words into a single circuit.  Each of the 4-bit static RAM modules
  1954. is configured as illustrated in the "DATA.LG" sample circuit.  When the top
  1955. switch is FALSE, the 3-state devices are active and output the contents of the
  1956. memory.  The next switch down is the write switch.  When it is set to FALSE,
  1957. the input data is set to the selected RAM module.  Notice the input data is
  1958. preset to TRUE, FALSE, TRUE, FALSE.  The next two switches select which of the
  1959. four RAM modules is accessed.  The last switch on the bottom is the clear
  1960. switch.  When it is set to FALSE, all four RAM modules are cleared.  It should
  1961. be set TRUE during normal operations.
  1962.  
  1963. This concludes the discussion on computer circuits.  I hope you now have a
  1964. better understanding of the fundamental logic circuits that comprise a
  1965. computer.
  1966.  
  1967. INTEGRATED CIRCUITS (IC)
  1968.  
  1969. An "Integrated Circuit" (IC) is a single piece of semiconductor material
  1970. containing multiple electronic components.  The original ICs only contained a
  1971. few components, possibly a single logic gate.  As the technology improved, the
  1972. components became smaller, and more gates were placed on a single chip.  Using
  1973. today's technology, over a million transistors can be placed on a single IC
  1974. chip representing hundreds of thousands of logic gates.
  1975.  
  1976. In the Logic Circuit Analysis program, the term "Integrated Circuit" (IC)
  1977. takes on a slightly different meaning.  The Logic Circuit Analysis library
  1978. contains both basic logic gates and Integrated Circuits (like Flip-Flops,
  1979. Counters, 4-bit ALU and 4-bit multiply circuit), which are circuits created
  1980. using the Logic Circuit Analysis program, saved in a file with the "LGL"
  1981. extension, and referenced in the library.  The "LOGIC.LGL" file contains all
  1982. the parameters and screen locations for each item in the library.  (See the
  1983. section below that describes this file format).  Each IC is stored in a
  1984. separate file.  As an example, the Exclusive OR gate is stored in the file
  1985. "XOR.LGL" located in the LGL subdirectory.  
  1986.  
  1987. You can view this circuit by changing to the LGL subdirectory in the Select
  1988. Sample Circuit menu.  
  1989.  
  1990.   From the Directories menu select the ".." item to move up one
  1991.   directory. 
  1992.  
  1993.   Select the "LGL" item to display the library circuits.  
  1994.  
  1995.   From the Circuits menu select "XOR.LGL."
  1996.  
  1997. You will notice that there are no switches for input. The first nodes created
  1998. correspond to the connection points.  By convention, the connection order is
  1999. inputs followed by outputs.  LGL files are not always easy to read, since they
  2000. use the fewest number of nodes necessary for the library.  Nodes can be moved
  2001. around on the screen, but if you delete one of the connection nodes, you
  2002. cannot simply recreate it.  Since the order in which the nodes were created is
  2003. essential to maintain compatibility with the "LOGIC.LGL" file.  Please do not
  2004. modify the LGL library files.
  2005.  
  2006. USER DEFINED ICs
  2007.  
  2008. Why did I discuss LGL files?  
  2009.  
  2010. Because you can create your own circuits and add them to the library.  The
  2011. last eight icons on the second page of the library are reserved for your use. 
  2012. They are stored in the files LGL\USER1.LGL through LGL\USER8.LGL.  The
  2013. connection nodes are already created and organized on the screen in a pattern
  2014. matching the icon connection points.  All you have to do is add your circuits
  2015. to these files.  You can embed other ICs into your circuit, the only
  2016. limitation is the 1,000 total logic gates which includes the logic gates
  2017. within each IC and the IC icon itself.  You can move the nodes around the
  2018. screen, but please do not delete them.  If you make a mistake in your user
  2019. defined IC file, you can start all over by copying the LGL\USER.LGL file into
  2020. the file you were working on.  This file provides a good starting point. 
  2021. Please do not modify the LGL\USER.LGL file.
  2022.  
  2023. I hope you enjoyed this tutorial and will continue to use this program to
  2024. explore other logic circuits.  This program allows you to try some circuits
  2025. without actually building the circuit.
  2026.  
  2027. SPECIFICATIONS
  2028.  
  2029.   REQUIREMENTS
  2030.   ────────────
  2031.   IBM-PC or compatible with 286 or later microprocessor
  2032.   1 MB of disk space
  2033.   300 KB minimum available RAM, (after DOS, drivers and TSR)
  2034.   400 KB maximum available RAM required for complex circuits and no EMS
  2035.   EGA or VGA graphics adapter with 256 KB of RAM installed
  2036.   Color Monitor
  2037.  
  2038.   SUPPORTS (but not required)
  2039.   ───────────────────────────
  2040.   Mouse (2 or 3 button) with MOUSE.SYS or MOUSE.COM device driver.
  2041.   Expanded Memory (EMS).  It will use 64 KB of EMS if available.
  2042.  
  2043.   DOS ENVIRONMENTAL VARIABLES
  2044.   ───────────────────────────
  2045.   TMP     Sets location of LOGIC.PCX and LOGIC.LG file, otherwise
  2046.           written to the default directory.
  2047.           Example: SET TMP=D:\
  2048.  
  2049.   MONITOR Can be set to EGA or VGA.  The program will automatically
  2050.           detect if an EGA or VGA adapter is installed.  The MONITOR
  2051.           variable will override the automatic detection.
  2052.           Example: SET MONITOR=EGA
  2053.  
  2054.   EMS     Can be set to OFF or NO to override auto-detection so not to
  2055.           use EMS memory even if it is available.
  2056.           Example: SET EMS=OFF
  2057.  
  2058.  
  2059.   PROGRAM LIMITS
  2060.   ──────────────
  2061.     112 Library Entries
  2062.   1,000 Logic Gates per circuit, including ICs and their logic gates
  2063.   3,000 Nodes per circuit
  2064.   7,000 Connections per circuit
  2065.      20 Connection terminals per IC
  2066.       8 Connections per node.
  2067.       8 User Definable Circuits SUMMARY OF KEYS
  2068.  
  2069.   OPENING MENU
  2070.           Cursor Keys - Highlight the desired item
  2071.           HOME - Highlight "Analyze Circuit"
  2072.           END - Highlight "Save and Exit"
  2073.           ENTER - Select the highlighted item
  2074.  
  2075.   SELECT SAMPLE CIRCUIT MENU
  2076.           PGUP, PGDN - Display additional pages of sample circuits
  2077.           Cursor Keys - Highlight the desired sample circuit
  2078.           HOME - Highlight the first sample circuit on this page
  2079.           END - Highlight the last sample circuit on this page
  2080.           ENTER - Select the highlighted sample circuit
  2081.           ESC, F10 - Exit this menu without selecting a sample circuit
  2082.  
  2083.   ANALYZE CIRCUIT
  2084.           F1 - Identify number of Gates, Nodes, and Connections
  2085.           Second F1 - Full screen help
  2086.           F5 - Online Tutorial (Tutor)
  2087.           F6 - Modify Circuit (Edit)
  2088.           LEFT and RIGHT - Highlight Switch or Clock
  2089.           UP or HOME - Set switch to up position
  2090.           DOWN or END - Set switch to down position
  2091.           ENTER - Toggle Switch
  2092.           + - Speed up the rate the screen is updated
  2093.           - - Slow down the rate the screen is updated
  2094.           PGDN - Speed up the clock rate
  2095.           PGUP - Slow down the clock rate
  2096.           w - Save screen into PC Paintbrush compatible file
  2097.           F10, ESC - Exit 
  2098.  
  2099.   MODIFY CIRCUIT
  2100.           F1 - Brief help
  2101.           Second F1 - Full screen help
  2102.           F2 - Redraw screen
  2103.           F3 - Move a logic gate (Node or IC)
  2104.           F4 - Access Library of Components 
  2105.           F5 - Online Tutorial (Tutor)
  2106.           F6 - Analyze Circuit (Calc)
  2107.           Cursor Keys - Move Cursor
  2108.           CTRL-BACKSPACE - Delete logic gate (Node or IC)
  2109.           ENTER - Make a Connection, or Lock it in position
  2110.           F10, ESC - Exit
  2111.  
  2112.   LIBRARY OF COMPONENTS
  2113.           F1 - Help (Second F1 for full screen help)
  2114.           Cursor Keys - Highlight logic gate (Node or IC)
  2115.           PGUP, PGDN - Switch Pages of Library Components
  2116.           ENTER - Select Logic Gate or IC
  2117.           F10, ESC - Exit
  2118.  
  2119. LIBRARY
  2120.  
  2121. The Library is based on the AND, OR, NAND, and NOR logic gates.
  2122. Each logic gate can contain between one and four inputs.
  2123. ICs are circuits created using the Logic Circuit Analysis program and made
  2124. available in the library.
  2125.  
  2126. The Library contains the following items:
  2127.  
  2128. Type              Description
  2129. ─────   ───────────────────────────────────────────────
  2130. INODE   Interconnect Node
  2131. VNODE   TRUE Node
  2132. VNODE   FALSE Node
  2133. SNODE   Switch Node
  2134. CLOCK   Clock Node
  2135. IC      Reserved
  2136. 3WAY    3-State Gate
  2137. NOR     NOT Gate (1-In NOR Gate)
  2138.  
  2139. AND     2-In AND Gate
  2140. AND     3-In AND Gate
  2141. OR      2-In OR Gate
  2142. OR      3-In OR Gate
  2143. NAND    2-In NAND Gate
  2144. NAND    3-In NAND Gate
  2145. NOR     2-In NOR Gate
  2146. NOR     3-In NOR Gate
  2147.  
  2148. AND     4-In AND Gate
  2149. OR      4-In OR Gate
  2150. NAND    4-In NAND Gate
  2151. NOR     4-In NOR Gate
  2152. IC      Integrated Circuit: XOR.LGL,      2-In Exclusive OR
  2153. IC      Integrated Circuit: XNOR.LGL,     2-In Exclusive NOR
  2154. IC      Integrated Circuit: SRLatch.LGL,  Set-Reset Latch
  2155. IC      Integrated Circuit: DLatch.LGL,   Data Latch
  2156.  
  2157. IC      Integrated Circuit: SRFF.LGL,     Set-Reset Flip-Flop
  2158. IC      Integrated Circuit: DFF.LGL,      Data Flip-Flop
  2159. IC      Integrated Circuit: DFFsc.LGL,    Data Flip-Flop, Preset and Clear
  2160. IC      Integrated Circuit: JKFFsc.LGL,   J-K Flip-Flop, Preset and Clear
  2161. IC      Integrated Circuit: FullAdd.LGL,  1-bit Full Adder
  2162. IC      Integrated Circuit: Add4.LGL,     4-bit Adder
  2163. IC      Integrated Circuit: Counter.LGL,  4-bit Asynchronous Counter
  2164. IC      Integrated Circuit: LScount.LGL,  4-bit Synchronous Counter with Load
  2165.  
  2166. IC      Integrated Circuit: 3state.LGL,   4-bit 3-State Gate
  2167. IC      Integrated Circuit: Data.LGL,     4-bit Data Latch
  2168. IC      Integrated Circuit: 2to4.LGL,     2 to 4 Line Decoder
  2169. IC      Integrated Circuit: 3to8.LGL,     3 to 8 Line Decoder
  2170. IC      Integrated Circuit: LU.LGL,       4-bit Logic Unit
  2171. IC      Integrated Circuit: AU.LGL,       4-bit Arithmetic Unit
  2172. IC      Integrated Circuit: ALU.LGL,      4-bit Arithmetic Logic Unit
  2173. IC      Integrated Circuit: Multiply.LGL, 4-bit Multiply IC      Integrated Circuit: ANDgate.LGL,  4-bit AND gate
  2174. IC      Integrated Circuit: SRFFsc.LGL,   Set-Reset Flip-Flop, Preset & Clear
  2175. IC      Integrated Circuit: ShiftReg.LGL, 4-bit Shift Register
  2176. IC      Integrated Circuit: AorB.LGL,     4-bit 1 of 2 word selector
  2177. IC      Integrated Circuit: 2Xbar.LGL,    2-line Cross Bar switch
  2178. IC      Integrated Circuit: 4Xbar.LGL,    4-line Cross Bar switch
  2179. IC      Integrated Circuit: User.LGL,     Reserved
  2180. IC      Integrated Circuit: Divide.LGL,   4-bit Divide
  2181.  
  2182. IC      Integrated Circuit: ECLNOT.LGL,   ECL-Type NOT Gate
  2183. IC      Integrated Circuit: 2AndNand.LGL, ECL-Type 2-In AND-NAND Gate
  2184. IC      Integrated Circuit: 3AndNand.LGL, ECL-Type 3-In AND-NAND Gate
  2185. IC      Integrated Circuit: 4AndNand.LGL, ECL-Type 4-In AND-NAND Gate
  2186. IC      Integrated Circuit: 2OrNor.LGL,   ECL-Type 2-In OR-NOR Gate
  2187. IC      Integrated Circuit: 3OrNor.LGL,   ECL-Type 3-In OR-NOR Gate
  2188. IC      Integrated Circuit: 4OrNor.LGL,   ECL-Type 4-In OR-NOR Gate
  2189. IC      Integrated Circuit: XorXnor.LGL,  ECL-Type 2-In Exclusive OR-NOR Gate
  2190.  
  2191.         . . .
  2192.  
  2193. IC      Integrated Circuit: User1.LGL,    User Defined IC
  2194. IC      Integrated Circuit: User2.LGL,    User Defined IC
  2195. IC      Integrated Circuit: User3.LGL,    User Defined IC
  2196. IC      Integrated Circuit: User4.LGL,    User Defined IC
  2197. IC      Integrated Circuit: User5.LGL,    User Defined IC
  2198. IC      Integrated Circuit: User6.LGL,    User Defined IC
  2199. IC      Integrated Circuit: User7.LGL,    User Defined IC
  2200. IC      Integrated Circuit: User8.LGL,    User Defined IC
  2201.  
  2202. SAMPLE CIRCUITS
  2203.  
  2204. The following examples can be found in the \LOGIC\LG sub-directory:
  2205.  
  2206. Filename                  Description
  2207. ───────────     ───────────────────────────────────────────────
  2208. 16XBAR.LG       16-line Cross Bar Switch
  2209. 1OF2.LG         1 of 2-line Selector
  2210. 1OF4.LG         1 of 4-line Selector
  2211. 2TO4.LG         2-bit to 4-line Decoder
  2212. 2XBAR.LG        2-line Cross Bar Switch
  2213. 3STATE.LG       3-State Gate
  2214. 3TO8.LG         3-bit to 8-line Decoder
  2215. 4BITADD.LG      4-bit Addition
  2216. 4BITSUB.LG      4-bit Subtraction
  2217. 4TO2.LG         4-line to 2-bit Encoder
  2218. 4XBAR.LG        4-line Cross Bar Switch
  2219. ALU.LG          4-bit Arithmetic Logic Unit
  2220. AORB.LG         4-bit wide 1 of 2-line Selector
  2221. AU.LG           4-bit Arithmetic Unit
  2222. CLOCK.LG        Clock formed by three NOT Gates
  2223. COUNTER.LG      4-bit Asynchronous Counter
  2224. DATA.LG         4-bit word Static RAM
  2225. DEMORGAN.LG     DeMorgan's Theorem Example
  2226. DFF.LG          Data Flip-Flop
  2227. DFFSC.LG        Data Flip-Flop with Preset and Clear
  2228. DLATCH.LG       Data Latch
  2229. FPMULTP.LG      8-bit Floating Point Multiplier
  2230. FULLADD.LG      Full Adder
  2231. HALFADD.LG      Half Adder
  2232. JKFFSC.LG       J-K Flip-Flop with Preset and Clear
  2233. LSCOUNT.LG      4-bit Synchronous Counter with Parallel input
  2234. LU.LG           4-bit Logic Unit
  2235. MULTIPLY.LG     4-bit Multiplier
  2236. NANDLOGC.LG     Logic Gates from only NAND Gates
  2237. NANDNOR.LG      NAND and NOR Gates
  2238. NORLOGIC.LG     Logic Gates from only NOR Gates
  2239. RAM.LG          4-word by 4-bit Static RAM
  2240. REGISTER.LG     4-bit Register
  2241. SHIFTREG.LG     4-bit Shift Register with Serial or Parallel input
  2242. SPSHREG.LG      4-bit Shift Register with Serial input
  2243. SRFF.LG         Set-Reset Flip-Flop
  2244. SRFFSC.LG       Set-Reset Flip-Flop with Preset and Clear
  2245. SRLATCH.LG      Set-Reset Latch
  2246. SRLATCHE.LG     Set-Reset Latch with Enable
  2247. SYNCOUNT.LG     4-bit Synchronous Counter
  2248. UDCOUNT.LG      4-bit Up or Down Synchronous Counter
  2249. XOR.LG          Exclusive OR Gate
  2250.  
  2251. LOGIC.LGL FILE FORMAT
  2252.  
  2253. LOGIC.LGL contains the specifications for each library entry.  There is one
  2254. line for each entry as follows:
  2255.  
  2256. TYPE NL NC NP  --- Locations x y ---  --- Parameters ---
  2257.  
  2258. where TYPE is:
  2259.    INODE - Interconnect Node
  2260.    VNODE - Fixed Value Node
  2261.    SNODE - Switch Node
  2262.    CLOCK - Clock or Pulse Node
  2263.    3WAY  - 3-State Logic Gate
  2264.    AND   - Logical AND
  2265.    OR    - Logical OR
  2266.    NAND  - Logical NAND (NOT AND)
  2267.    NOR   - Logical NOR (NOT OR)
  2268.    IC    - Integrated Circuit - Logic circuit made from above logic gates
  2269.                                 and stored in separate files
  2270.  
  2271. NL: Number of Locations
  2272. NC: Number of Connections must be less then or equal to NL
  2273. NP: Number of Parameters
  2274.  
  2275. --- Locations x y ---
  2276. Locations specified in x y pairs relative to upper left corner of icon.  The
  2277. first NC locations are the connections, any additional locations are for
  2278. Resistor current, Potentiometer % turns, or INODE Voltage labels.
  2279.  
  2280. --- Parameters --- 
  2281. The number and type of parameters depends on the TYPE as follows:
  2282.  
  2283. TYPE  NL NC NP           Locations                     Parameters        
  2284. ───── ── ── ──  ───────────────────────────   ───────────────────────────
  2285. INODE  1  1  0  connection
  2286. VNODE  1  1  1  connection                    Logical Value 0 or 1
  2287. SNODE  1  1  0  connection
  2288. CLOCK  1  1  0  connection
  2289. 3WAY   3  3  0  input, enable, output
  2290. AND    ?  ?  0  inputs, output
  2291. OR     ?  ?  0  inputs, output
  2292. NAND   ?  ?  0  inputs, output
  2293. NOR    ?  ?  0  inputs, output
  2294. IC     ?  ? -1  inputs, outputs               FILENAME.LGL
  2295.           Up to 20 Connections
  2296.  
  2297. The Library are based on the following Logic Gates:
  2298. AND, OR, NAND and NOR can have from 1 to 4 inputs, but only one output.
  2299. A NOT is a single input NOR (or NAND).
  2300. ICs are all predefined Logic Circuits that may contain other ICs.
  2301.  
  2302. Integrated Circuits (ICs) files are stored in the \LOGIC\LGL sub-directory.
  2303. ICs are all predefined Logic Circuits that contain Logic Gates or other ICs.
  2304.  
  2305. LG AND LGL FILE FORMATS
  2306.  
  2307. Files with the extension "LG" are sample circuit files located in the LG sub-
  2308. directory.  Files with the extension "LGL" are library (IC) circuit files
  2309. located in the LGL sub-directory.  Both files contains circuit created by the
  2310. Logic Circuit Analysis program, and have the same format:
  2311.  
  2312. The first line contains two numbers as follows:
  2313.  
  2314. NG NN
  2315.   where   NG = Number of Logic Gates or ICs
  2316.           NN = Number of Nodes (Interconnect, Fixed, Switch, or Clock)
  2317.  
  2318. The next NG lines contains the logic gates one per line as follows:
  2319.  
  2320. LIB ROW COL N N1 N2 ...
  2321.   where   LIB = Library entry (0-111)
  2322.           ROW = Screen row location of icon (0-299)
  2323.           COL = Screen column location of icon (0-79)
  2324.           N   = Number of connection terminals
  2325.           N1, N2, ... = Node corresponding to each connection
  2326.                   Nodes are numbered starting with 1000
  2327.  
  2328. The next NN lines contains the nodes, one per line as follows:
  2329.  
  2330. LIB ROW COL N  G1 C1  G2 C2 
  2331.   where   LIB = Library entry (0-111)
  2332.           ROW = Screen row location of icon (0-299)
  2333.           COL = Screen column location of icon (0-79)
  2334.           N   = Number of connections
  2335.           G1, G2, ... = Logic Gate (0-999), or Node
  2336.           C1, C2, ... = Connection on logic gate or Node G1, G2, ...
  2337.